I have two drop down lists - ddl1 and ddl2 and a button.
I select a value from ddl1 which fires ddl1_selectedIndexChanged event.
On occurance of abovesaid event, ddl1 selected value goes to database in a SELECT statement in WHERE Clause to fetch some rows of required data.
This new data table now populates ddl2.
Now I select a value from ddl2.
I press the button.
Now I want to use the ddl2_selected value in button_click event.
What happens is when I press the button, ddl1_selectedIndexChanged event fires unexpectedly and binds the ddl2 once again and hence I loose the ddl2_selectedValue.
I have not used AJAX or Update Panel in my page.
ASP.NET 4.0.
ddl1 - EnableViewState True, PostBack = True
ddl2 - EnableViewState True, PostBack = False
Do you have something in the Page_Load event that is calling the same thing as the ddl1_selectedIndexChanged event? If so, you need to use if(!isPostBack) in the Page_Load method.
I resolved the issue by going through a couple of more blogs over net.
What I was doing was I wrote these entire set of controls in asp Panel.
The viewState property of this panel was set to False.
As soon as I changed it to true, the unwanted selectedindexchanged event got suppressed.
This got me through. :)
But, it was a hunch.
I did not yet get the reason why this happened ?
RabbitsFoot
0 Points
3 Posts
Button Click event fires DropDownList_SelectedIndexChanged event but I don't want it.
Dec 06, 2012 04:58 PM|LINK
Hi
I have two drop down lists - ddl1 and ddl2 and a button.
I select a value from ddl1 which fires ddl1_selectedIndexChanged event.
On occurance of abovesaid event, ddl1 selected value goes to database in a SELECT statement in WHERE Clause to fetch some rows of required data.
This new data table now populates ddl2.
Now I select a value from ddl2.
I press the button.
Now I want to use the ddl2_selected value in button_click event.
What happens is when I press the button, ddl1_selectedIndexChanged event fires unexpectedly and binds the ddl2 once again and hence I loose the ddl2_selectedValue.
I have not used AJAX or Update Panel in my page.
ASP.NET 4.0.
ddl1 - EnableViewState True, PostBack = True
ddl2 - EnableViewState True, PostBack = False
Please help me out.
Thanks in advance.
AZMatt
Star
10638 Points
1896 Posts
Re: Button Click event fires DropDownList_SelectedIndexChanged event but I don't want it.
Dec 06, 2012 05:21 PM|LINK
Do you have something in the Page_Load event that is calling the same thing as the ddl1_selectedIndexChanged event? If so, you need to use if(!isPostBack) in the Page_Load method.
Matt
RabbitsFoot
0 Points
3 Posts
Re: Button Click event fires DropDownList_SelectedIndexChanged event but I don't want it.
Dec 07, 2012 04:43 PM|LINK
Hi Everyone,
I resolved the issue by going through a couple of more blogs over net.
What I was doing was I wrote these entire set of controls in asp Panel.
The viewState property of this panel was set to False.
As soon as I changed it to true, the unwanted selectedindexchanged event got suppressed.
This got me through. :)
But, it was a hunch.
I did not yet get the reason why this happened ?
Explanations are most welcome.
@Matt: Thanks fot the concern.
Amy Peng - M...
Star
10132 Points
959 Posts
Microsoft
Re: Button Click event fires DropDownList_SelectedIndexChanged event but I don't want it.
Dec 10, 2012 04:57 AM|LINK
Hi RabbitFoot
Please refer the concepts about OnSelectedIndexChanged Method, AutoPostBack, EnableViewState, you will have a full understanding of DropDownList.
OnSelectedIndexChanged Method
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.onselectedindexchanged.aspx
AutoPostBack Property
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.autopostback.aspx
EnableViewState
http://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate.aspx
DropDownList Class
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.dropdownlist(v=VS.110).aspx
Regards,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store