RadioButtonList Event Not Firing - Postback Issues


I’m having issues getting the selected value of a RadioButtonList. We’re retrieving 12 records at a time from a data source and populating the list. Our policy is not to use .NET paging because of the potentially large number of records. So, I have to do data binding on page load, whether postback or not.

My RadioButtonList has AutoPostBack set to true; here’s the complete declaration:

<asp:RadioButtonList ID=“rbSurveyList” runat=“server” Width=“100%” CellPadding=“0” CellSpacing=“0” OnSelectedIndexChanged=“rbSurveyList_SelectedIndexChanged” AutoPostBack=“True” AppendDataBoundItems=“True” DataTextField=“Name” DataValueField=“SurveyID”>

My pageload instantiates a separate data layer and then data binds:

surveyData = new SurveySummaryData();
rbSurveyList.DataSource = surveyData.GetSurveyList(iPageNumber);

The data binding works fine, but I’m at a loss to get the selected value on postback, even after reading several forum posts. I’m assuming that the form post itself would pass a value, but I can’t even find that parameter in the Request object (note that this is inside a master page, so it appends the standard .NET prefixes to all the form objects).

Any ideas? The boss keeps saying “this is a simple form - what’s taking so long?”.


Jim Stanley

Are you checking IsPostBack before DataBinding()?

I tried - with bad results. Maybe the paging method needs to change: I have “Next” and “Previous” links at the bottom of one panel, with their NavigateURL properties set to increment or decrement a PageNumber param added to the page URL. Thus, when the links are clicked, it’s not a postback.

I must be missing the issue, but right now I need to data bind regardless of whether it’s a postback or not. Would LinkButtons instead of links work better? In which case, how to increment/decrement the page? I’ve had really bad luck trying to change the form’s Action value (we’re on .NET 2.x). And is there really no way of directly accessing the radio/check box list values in the Request object? I tried Request[rbSurveyList.ClientID] and got “object not found”.

[As an aside: I get the feeling that the programming practices in our shop don’t work very well with .NET - we just got off trying to do a wizard-style registration app without the wizard component and just struggled with it on a daily basis. It seems that we have to learn a completely new way of creating apps, one that’s utterly incompatible with traditional web programming.]

Jim Stanley
Blackboard Connect Inc.

Hitting web forms from completely traditional style of programming is definitely tilting at windmills, you might want to check out ASP.NET MVC if you want to keep to a more traditional web style while leveraging .NET.

The fact that you are binding data when you are posting back is killing your events–basically they are getting overwritten before things have fired. Using GET to page shouldn’t effect your need to databind PostBacks at all.

On getting at the posted data, remember that you still are using HttpPost and the concept of RadioButtonLists does not exist there. Rather, you need to grab the POST data for each radio button just like you would do it in more primitive frameworks. That said, if you are diving into POST (Request.Form) in ASP.NET webforms you are almost always doing something wrong.

This problem happens when you have EnableViewState=false for the page or the control. How is that part on your code?

Have just discovered something: this is inside a master page and that appears to be the source of the problem. Without the master page, the code works correctly. I made sure that the master page’s EnableViewState was set to true, and the same problem exists.

So I’m not completely crazy…

I think I’ve got it. The master page’s form.enableviewstate was set to false; setting it to true gets things going again. There are some other issues, but those appear to be solvable. Thanks all for your patience - if I could only regrow the hair I’ve pulled out…