views:

203

answers:

3

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 that 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 .

+1  A: 

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.

citronas
i do the binding on a button click , is that the same? and should i add something like ` DDLName.OnindexChanged += DDLOnIndexChanged ` ?
Madi D.
Is the DDL fixed in your markup? Then I do recommend using eventhandler stuff in the markup. Add OnIndexChanged="DLLOnIndexChanged" as property to your DDL. Ensure that the "AutoWireUpEvent" property of the page is set to true.
citronas
okie i will try that.. i am also editing the question, adding more details..
Madi D.
Did u see my edit?
citronas
yes , sadly still doesnt work :S , found another ` viewstate=false ` on the UpdatePanel itself (i am maintaining the code) , after removing it the page work fine now,BUT everytime i press the button that performs the binding, the DDL gets updated again and the items doubled..
Madi D.
Have you tried the property 'AppendDataBoundItems=false'?
citronas
+1  A: 

Is the DDL's AutoPostBack property set to true?

peter3
Yes it is.. (filler)
Madi D.
A: 

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.

awright18
I already checked on all of these, i even tried to re-write the event handler in many different ways.
Madi D.