Hello i've come across a peculiar thing here, i don't understand whats going on.
Here is my webpage :
Code:
<%@ Page Language="C#" MasterPageFile="~/mymaster.master" AutoEventWireup="true" CodeFile="Advising.aspx.cs" Inherits="Advising_Default" Title="Advising Webpage" %>
<asp:Content ID="Content2" ContentPlaceHolderID="PageContent" Runat="Server">
<table width="100%"><tr><td>
Student Name : <asp:TextBox runat="server" ID="StudentName" />
</td><td width="200">
<asp:RadioButtonList ID="StudentType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="StudentType_SelectedIndexChanged">
<asp:ListItem Text="Undergraduate Student" Selected="true" />
<asp:ListItem Text="Graduate Student" />
</asp:RadioButtonList>
</td><td>
Advising Type : <asp:DropDownList runat="server" ID="choose_AdvisingType" />
</td><td>
Degree : <asp:DropDownList runat="server" ID="choose_AdvisingDegree" />
</td>
</tr><tr><td colspan="3">
<br />
Additional Description : <asp:TextBox runat="server" ID="AdditionalDescription" TextMode="multiLine" Width="80%" />
</td></tr></table>
....
And here is my codebehind for that page :
Code:
public partial class Advising_Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
populateDropDowns();
loadRecord(instructionID);
}
}
protected void StudentType_SelectedIndexChanged(object sender, EventArgs e)
{
populateDropDowns();
}
private void populateDropDowns(){
//populates the two ddls based on the radiolist selecteditem
if(StudentType.SelectedItem.Value.Equals("Undergraduate Student")){
bll.fillUGradDegrees(choose_AdvisingDegree);
bll.fillUGradAdvisingTypes(choose_AdvisingType);
} else if(StudentType.SelectedItem.Value.Equals("Graduate Student")){
bll.fillGradAdvisingTypes(choose_AdvisingType);
bll.fillGradDegrees(choose_AdvisingDegree);
}
}
public void loadRecord(int instructionID)
{
Instruction_Advising_Data data = bll.loadRecord(instructionID);
StudentName.Text = data.StudentName;
AdditionalDescription.Text = data.AdditionalInfo;
//choose grad/undergrad
try{
//StudentType.Items.FindByText(data.StudentType).Selected = true;
} catch { /* do nothing*/ }
//populate the drop downs accordingly
populateDropDowns();
}
...
Okay, so this page works fine and dandy, everything as it should with the code above That is, when the user selects a different radiobutton value, the dropdown values change.
But as soon as I try to set the radio list's selected value myself (ie uncomment the line in red : StudentType.Items.FindByText(data.StudentType).Sel ected = true; ), the page does not work properly. The autopostback doesnt happen nor is the StudentType_SelectedIndexChanged() event fired. Looking at the page source, one can see that the javascript wireup for the selectindexchanged event isn't even hooked up.
Whats going on and how can I fix my code so that I can set the selecteditem in my codebehind and still have my postback events fire that changes the ddls ?