ASP.NET: DropDownList onIndexChanged Event Not firing
I have a webpage inheriting a masterpage, The webpage has a DropDownList (DDL) in it, with an OnIndexChanged
Event attached to it.
The problem simply is that the event is not firing, even though a callback occurs (and page_load()
events are called)..
I did some searching and read that having the page's viewstate
set to false, would cause a similar issue, and checking the Masterpage (i dont have access to modify it though) i found it set to false, would t开发者_如何学Chat be the reason ?
Also is it possible to set the viewstate = true
on the webpage (the inheriting page) ? would it override the original viewstate = false
on the master page?
EDIT :
The DDL is shown (using Ajax) when a button is a clicked , so initially (on Page_load() DDL.visible = false
, but in the button_click()
event i set DDL.visible = true
which also populates a datareader that gets bound to the DDL .
Is the DDL's AutoPostBack property set to true?
Do you perform a manually Databind() in the Page_Load() Method? In that case the OnIndexChanged Event will get lost. (Therefore the solution would be not to bind on postback)
Edit (after question clarification): I think a PostBackTrigger will help you to the desired solution.
There are a few obvious things to check. The following 3 things must be setup correctly for yo your page in the page directive at the top of the page.
AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default"
Next in the <asp:DropDownList
control markup all of these attributes are required to be filled out
ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
Then finally you must have a corresponding handler for the event in your code behind
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
If all those things are true the only thing that could stop the page from posting on a change in the selected index is some javascript that returns false on a post request.
If none of these help make a new page and copy and paste your code to it, then build and run again.
精彩评论