c# - Drop Down List resets -
my drop down list resets default when try select item, , doesn't trigger's code behind method when put line break , try debug it:
here's markup,
<script type="text/javascript"> function bringpopup() { $.blockui({message: $('#anotherup'), css: { width: '600px' } }); } </script> <div id="anotherup" style="display: none; cursor: default"> <asp:updatepanel id="updatepanel2" runat="server" updatemode="conditional" childrenastriggers="false"> <contenttemplate> <asp:dropdownlist id="drop1" runat="server" enableviewstate="true" autopostback="true" onselectedindexchanged="drop1_selectedindexchanged"/> </contenttemplate> <triggers> <asp:asyncpostbacktrigger controlid="drop1" eventname="selectedindexchanged" /> </triggers> </asp:updatepanel> </div> <asp:updatepanel id="updatepanel1" runat="server" updatemode="conditional" childrenastriggers="true"> <contenttemplate> <input type="button" id="button3" value="click me bring pop up" onclick="bringpopup()" /> <br /> </contenttemplate> </asp:updatepanel>
here's code behind,
public partial class myusercontrol : usercontrol { protected void page_load(object sender, eventargs e) { if (!ispostback) { binddropdownlist(); } } protected void binddropdownlist() { using (sqldatasource ds = new sqldatasource(connectionstring(), selectcommand())) { system.data.dataview dv = (system.data.dataview)ds.select(datasourceselectarguments.empty); if (dv.count > 0) { drop1.datasource = ds; drop1.datatextfield = "username"; drop1.databind(); drop1.items.insert(0, "please select username "); } } updatepanel2.update(); } protected void drop1_selectedindexchanged(object sender, eventargs e) { //while debugging never hits break point. } }
update
if comment out updatepanel2
ddl doesn't reset still doesn't trigger's code behind method.
this common problem sharepoint event handling. please try below code in page load.
protected void page_load(object sender, eventargs e) { drop1.selectedindexchanged += new eventhandler(drop1_selectedindexchanged); if (!ispostback) { binddropdownlist(); } }
Comments
Post a Comment