asp.net - Dropdown in .net usercontrol not maintaining state -
this fundamental , stupid i've missed, various workarounds causing me such huge headaches really, need understand basic problem here in order find best solution.
i have usercontrol contains drop-down list.
<asp:dropdownlist id="ddlorderstatus" autopostback="true" runat="server" cssclass="textbox"> <asp:listitem value="8">pending</asp:listitem> <asp:listitem value="9">on hold</asp:listitem> <asp:listitem value="11">complete</asp:listitem> <asp:listitem value="12">cancelled</asp:listitem> </asp:dropdownlist>
it nothing in page_load event.
this in turn contained in page which, in it's page_load event databinding on repeater controls on page doesn't touch control containing ddl. there no ajax on page.
the dropdownlist - - set autopostback = true. postback code looks this:
private sub ddlorderstatus_selectedindexchanged(byval sender object, byval e system.eventargs) handles ddlorderstatus.selectedindexchanged dim ddl dropdownlist = directcast(sender, dropdownlist) dim currentsorting string = request.querystring("sort") dim currentpaging string = request.querystring("page") response.redirect(string.format("~/admin/orders/manage/0?sort={0}&page={1}&status={2}", currentsorting, currentpaging, ddl.selectedvalue)) end sub
so when ddl changed, page double postback. see no way avoid need postback value in ddl , postback new data server based on value.
anyway, long , short of when dropdownlist fails maintain state. select value, code job it's supposed - gets selected value posts again returning new expected set of data - , on loading again dropdownlist in default form.
this pernicious problem me because of double-postback: if try , set value of ddl equal what's in querystring have, effecitvely, set value permanently because page_load - value set - occurs before events processed , value stays unchanged. tried moving code changed selectedvalue of ddl render, seemed although selected value had changed far user see, selected value still default value during processing , treated such.
i tried setting selectedvalue in session , clearing populated. worked scenarios, unfortunately page contains javascript can cause post - , can't set session client-side javascript. idea had go out window.
i'm @ loss here - apparently simple problem has eaten whole day of time. can either tell me why state isn't being maintained on control and/or suggest way show right value after postback without turning selection permanent one?
cheers, matt
in page load:
// set selected order status when page first loads, not on postbacks. if( !page.ispostback ) { ddlorderstatus.selectedvalue = request.querystring("status"); }
footnote:
i see no way avoid need postback value in ddl , postback new data server based on value.
you javascript
Comments
Post a Comment