Modify control's Enabled property without postback?
Posted on 2010-11-10
I have within the EmptyDataTemplate of a GridView a RadioButtonList, a DropDownList and a DetailsView control. I would like, based on which of the two values of the RBL is selected, for the DDL or DV control's Enabled property to change to true/false. I've accomplished this thru the following code-behind in the RBL's SelectedIndexChanged command but this requires AutoPostBack which causes the user to lose their place on the page as the page reloads scrolled to the top etc. It's not very elegant :( Is there a better way?
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
RadioButtonList rbl = (RadioButtonList)sender;
DropDownList ddl = (DropDownList)(rbl.NamingContainer.FindControl("DropDownList1"));
DetailsView dv = (DetailsView)(rbl.NamingContainer.FindControl("DetailsView1"));
if (rbl.SelectedValue == "1")
ddl.Enabled = true;
dv.Enabled = false;
ddl.Enabled = false;
dv.Enabled = true;