Reputation: 10618
I have the following ASP.Net
code:
code.aspx:
<asp:UpdatePanel ID="upMain" runat="server">
<ContentTemplate>
<table>
<tr>
<td>DropDownList One</td>
<td>
<asp:DropDownList ID="ddlOne" runat="server" AutoPostBack="true"
OnSelectedIndexChange="ddlOne_SelectedIndexChanged" />
</td>
<td>DropDownList Two</td>
<td>
<asp:DropDownList ID="ddlTwo" runat="server" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
code.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlTwo.Visible = false;
}
}
protected void ddlOne_SelectedIndexChanged(object sender, EventArgs e)
{
ddlTwo.Visible = true;
}
What I Expect:
This code is supposed to make ddlTwo
visible upon ddlOne
's selected index changing.
What Actually Happens:
Upon changing the index of ddlOne
, the ddlOne_SelectedIndexChanged
function runs (test with debug) and the ddlTwo.Visible = true;
runs too but the and the property is changed as I step through the process but the moment the function is over and I want to see my results (i.e. the visible ddlTwo
control), there's no result.
If anyone can spot the issue, please let me know. Thank you!
Upvotes: 1
Views: 720
Reputation: 35524
Change this line
OnSelectedIndexChange="ddlOne_SelectedIndexChanged"
to
OnSelectedIndexChanged="ddlOne_SelectedIndexChanged"
and it should work.
Upvotes: 1
Reputation: 7490
try
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlOne"
EventName="SelectedIndexChanged" />
</Triggers>
inside update panel.
Upvotes: 2