asp.net - Dropdown in listview SelectedIndexChanged doesn't work first time but does after -
i've searched high , low, can't seem find out what's happening this. i've simplified code, have taken basic , still have same problem.
i have drop downwards list in a repeater (in web form master page):
<asp:dropdownlist id="ticketquantityddl" runat="server" cssclass="qtyddl" autopostback="true" onselectedindexchanged="ticketquantityddl_selectedindexchanged" causesvalidation="false" selectedindex='<%# cint(eval("quantity")) - 1%>'> <asp:listitem value="1">1</asp:listitem> <asp:listitem value="2">2</asp:listitem> <asp:listitem value="3">3</asp:listitem> <asp:listitem value="4">4</asp:listitem> <asp:listitem value="5">5</asp:listitem> <asp:listitem value="6">6</asp:listitem> </asp:dropdownlist>
handler
protected sub ticketquantityddl_selectedindexchanged(sender object, e eventargs) myliteral.text = "selected index changed handled..." end sub
the first time page loaded if alter ddl the page posted - selected index alter handler not fired (i've stepped through code, page.ispostback true). every time after handler works unless page total reloaded.
things i've tried:
manually adding handleronitemcreated
manually adding handler onitemdatabound
manually registering command async postback scriptmanager using onclientselectedindexchanged
trigger postback client removing autopostback
, of above again... i've used page.request.params("__eventtarget")
verify when partial postback fired command drop down. even though viewstate enabled i've tried specifying command , page directly. disabling validation. i've tried not binding value of drop downwards , leaving no selected value , manually setting initial selected value - no dice. tried removing update panel, same issue. things not happening here.
i'm not rebinding on postif not page.ispostback... databind...
i'm not selecting same value/first item in drop down this isn't auto id problem, controls id remain same through postbacks. i'm not doing funky other binding repeater list of objects. why isn't handler firing first time? after first time works intended.
update
i've replicated exact same behaviour in list view. due time constraints i've used approach i'd know how prepare or @ to the lowest degree know why doesn't work.
update 2
i've tested functionality bog standard web form , functions correctly. beingness in contentplaceholder masterpage, script manager or update panel. it's if event handler dropdown registered after first post back, i've tried registering handler in databound
, in page loadcomplete
events, same thing still happens.
update 3
i've since changed list view, i'm having exact same issue though.
this on web form master page, master page contains script manager, list view in update panel, although i've tried removing , still have same issue. i've not included onselectedindexchanged code, i've made simple changing text of literal - doesn't work first post back, second.
i had specified list items manually have changed programatically @ itemdatabound, still no difference.
as stated above when check command caused postback it's ddl, doesn't fire selectindexchanged first time. i've tried specifying onselectedindexchange in command itself, still no dice.
page load ,bind, list view , on item created code.
page load
protected sub page_load(byval sender object, byval e system.eventargs) handles me.load if not page.ispostback dim _basket = sessionhandler.getsessionobject(sessionhandler.sessionobjects.basket) if _basket nil orelse directcast(_basket, basketcontainer).basketitemlist.count = 0 basketsectioncontainer.visible = false alertliteral.text = alertgenerator.getalerthtml("no items in basket", "there no items in basket, please utilize menu above navigate site.", alertgenerator.alerttype.warning) if _basket isnot nil sessionhandler.removesessionobject(sessionhandler.sessionobjects.basket) exit sub else dim lbasket = directcast(_basket, basketcontainer) bindbasket(lbasket) end if end if end sub
bind
private sub bindbasket(lbasket basketcontainer) basketlistview.datasource = lbasket.basketitems basketlistview.databind() bindtotals(lbasket) 'this sets text of literals on page outside of listview if lbasket.postage postageddl.visible = true 'this outside of list view end if end sub
item created
private sub basketlistview_itemcreated(sender object, e listviewitemeventargs) handles basketlistview.itemcreated dim qtyddl dropdownlist = directcast(e.item.findcontrol("ticketquantityddl"), dropdownlist) addhandler qtyddl.selectedindexchanged, addressof ticketquantityddl_selectedindexchanged end sub
_item info bound _
private sub basketlistview_itemdatabound(sender object, e listviewitemeventargs) handles basketlistview.itemdatabound dim info basketitem = directcast(e.item.dataitem, basketitem) dim qtyddl dropdownlist = directcast(e.item.findcontrol("ticketquantityddl"), dropdownlist) integer = 1 6 qtyddl.items.add(new listitem(i.tostring, i.tostring)) next qtyddl.datatextfield = data.basketitemid.tostring 'no command arg ddl using this, i've tested without, doesn't create difference. select case data.baskettype case basketinfo.basketitemtype.discountedtickets, basketinfo.basketitemtype.tickets, basketinfo.basketitemtype.goods 'tickets , goods... qtyddl.items.findbyvalue(data.quantity.tostring).selected = true case else 'non ticket or goods type, disable quantity selection qtyddl.items.findbyvalue("1").selected = true qtyddl.enabled = false end select end sub
_list view _
<asp:listview id="basketlistview" runat="server"> <layouttemplate> <table class="cart-table responsive-table"> <tr> <th>item</th> <th>description</th> <th>price</th> <th>quantity</th> <th>total</th> <th></th> </tr> <asp:placeholder id="itemplaceholder" runat="server" /> </table> <table class="cart-table bottom"> <tr> <th> <asp:button id="applydiscountcodebutton" runat="server" cssclass="button color pull-right" text="apply code" /> <asp:textbox id="discountcodetextbox" runat="server" cssclass="discount-tb pull-right" /> </th> </tr> </table> <div class="clearfix"></div> </layouttemplate> <itemtemplate> <tr> <td> <img src="/images/shows/<%# eval("imageurl")%>.jpg" alt="<%#eval("basketitemtitle")%>" class="basketimg" /></td> <td class="cart-title"> <a href="#"><%#eval("basketitemtitle")%></a> <br /> <%# string.format("{0:dddd} {1} {0:mmmm yyyy} | {0:hh:mm}", eval("performancestarts"), eval("ordinalday"))%> <br /> <%# eval("venuetitle")%> </td> <td> <%#eval("pricebandtype")%> <br /> @ <%# string.format("{0:c}", eval("pricebandvalue"))%> </td> <td> <asp:dropdownlist id="ticketquantityddl" runat="server" cssclass="qtyddl" autopostback="true" clientidmode="static" /> </td> <td class="cart-total"><%#string.format("{0:c}", eval("basketitemtotalvalue"))%></td> <td> <asp:linkbutton id="removelinkbtn" runat="server" cssclass="cart-remove" commandname="removebasketitem" commandargument='<%#eval("basketitemid")%>' /> </td> </tr> </itemtemplate> </asp:listview>
since dropdown in within repeater, can seek next alternative instead. add together onitemcommand repeater. should trigger event on selection alter in dropdown. in onitemcommand need cast sender dropdownlist able selected value of dropdown
asp.net .net vb.net postback repeater
No comments:
Post a Comment