c# - asp:label change visibility after hiding it -
i've got asp:label
, asp:dropdownlist
want able switch , forth between visible , invisible when clicking on buttons. right now, code looks like
aspx file
<asp:label associatedcontrolid="statusfilter" id="statusfilterlabel" runat="server" cssclass="filterlabel">status <asp:dropdownlist id="statusfilter" runat="server" cssclass="filterinput" autopostback="true" onselectedindexchanged="anyfilter_selectedindexchanged" appenddatabounditems="true"> <asp:listitem selected="true" value=" 0"><all></asp:listitem> </asp:dropdownlist> </asp:label> <asp:button text="all" id="alltabbutton" cssclass="tabbutton" runat="server" onclick="alltab_click" /> <asp:button text="arrived" id="arrivedtabbutton" cssclass="tabbutton" runat="server" onclick="arrivedtab_click" />
code behind
protected void alltab_click(object sender, eventargs e) { alltabbutton.cssclass = "tabbuttonclicked"; arrivedtabbutton.cssclass = "tabbutton"; statusfilter.visible = true; statusfilterlabel.visible = true; } protected void arrivedtab_click(object sender, eventargs e) { alltabbutton.cssclass = "tabbutton"; arrivedtabbutton.cssclass = "tabbuttonclicked"; statusfilter.visible = false; statusfilterlabel.visible = false; }
the problem if try set visible=true
after setting visible=false
give me error unable find control id 'statusfilter' associated label 'statusfilterlabel'.
i tried doing other things instead of using visible, setting style: statusfilter.style.add("display", "block")
, setting cssclass: statusfilter.cssclass = "displayblock"
but resulting error showed up.
an asp:panel work, i'm avoiding using because want asp:label , asp:dropdownlist line several other labels , dropdownlists; putting in panel make them not line properly.
i'm guessing there i'm missing, don't get, can't seem figure out is. if has clue what's happening, appreciate help!
it's not able find control on postback because it's child of statusfilter. move input field outside of label:
<asp:label associatedcontrolid="statusfilter" id="statusfilterlabel" runat="server" cssclass="filterlabel">status </asp:label> <asp:dropdownlist id="statusfilter" runat="server" cssclass="filterinput" autopostback="true" onselectedindexchanged="anyfilter_selectedindexchanged" appenddatabounditems="true"> <asp:listitem selected="true" value=" 0"><all></asp:listitem> </asp:dropdownlist>
Comments
Post a Comment