Radio button stopped working after conversion from ASP.NET 1.1 to ASP.Net 3.5

[I'm posting our problem and solution below as an FYI. If you have an official statement from Microsoft or a representative organization about this issue, I'll mark that as an answer. Otherwise, my post below will serve as the answer].

The Problem:

We took a ASP.Net 1.1 program and converted it to ASP.Net 3.5. The page initially displays correctly with one radio button selected by default and a list of items ("List A"). When we clicked the other radio button, it then displayed List B correctly. When we clicked the originally selected radio button, the first list, List A, would not redisplay. The radio buttons are part of a RadioButtonList control.

What we did to debug: This is for a program which resides on a company intranet. Due to it being .Net 1.1, the program is heavily targeted towards Internet Explorer - the JavaScript doesn't run on other browsers. F12 developer tools brings up the JavaScript debugging console in Internet Explorer. Attaching to the IIS 7.5 process (w3wp.exe) with Visual Studio allowed us to view C# server code errors.

What we found: AutoPostBack was set to true on the RadioButtonList, which contained the List items which were radio buttons. As a result ASP.Net + C# dynamically generates the doPostBack function in the "onclick" event of the radio button. HOWEVER: no doPostBack function for the onclick was being generated for the default selected radio button. I believe this is a bug in the ASP.Net 3.5 framework and the RadioButtonList control.

edit: Removing solution from question and posting as answer to avoid question closing. Thanks @Jon P for the heads-up.

Answers:

Answer

[I'm posting our problem and solution in this initial post as an FYI. If you have an official statement from Microsoft or a representative organization about this issue, I'll mark that as an answer. Otherwise, this post will serve as the answer].

Solution:

1) We set AutoPostBack to false for the RadioButtonList control.

2) In the PreRender event for the page, we manually add the new doPostBack function to each List item in the radio button list by looping through the list items in the RadioButtonList.

3) The code is as follows:

for (int i = 0; i < rbList.Items.Count; i++)
{
    rbList.Items[i].Attributes.Add("onclick", "javascript:setTimeout('__doPostBack(\\'rbList$" + i + "\\',\\'\\')', 0)");
}

4) The code in the onclick event function call matches the structure of what ASP.Net 3.5 + C# automatically generate.

After this fix, both radio buttons had onclick events functions and original functionality was restored.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.