<asp:panel id="filterbanners" runat="server" visible ="false"> <h3> testing </h3> </asp:panel>
i'm trying set panel visibility true in way, doesn't work:
page.clientscript.registerstartupscript(this.gettype(), "scriptblock", "$('#filterbanners').show();", true);
or
scriptmanager.registerstartupscript(this, this.gettype(), "showcode5", "$('#filterbanners').show();", true);
the id filterbanners
of panel changed asp.net generated html jquery wont find it. need use clientid
instead of server id in jquery / javascript access panel.
scriptmanager.registerstartupscript(this.gettype(), "scriptblock", "$('#"+ filterbanners.clientid+"').show();", true);
if have .net framework can set clientidmode "static" let asp.net keep client id same server id.
the clientid value set value of id property. if control naming container, control used top of hierarchy of naming containers controls contains.
you can use class selector panel need assign class panel first.
html
<asp:panel id="filterbanners" runat="server" cssclass="panel-class" visible ="false"> <h3> testing </h3> </asp:panel>
code behind
scriptmanager.registerstartupscript(this.gettype(), "scriptblock", "$('.panel-class').show();", true);
edit 1
note have ensure jquery loaded before script executed, try using native javascript method access panel.
edit 2
you hiding panel setting visible="false"
in html result in no html generated panel javascript not find panel. have set visible property true in html generate html
it.
the following code tested , working.
html
<asp:panel id="filterbanners" runat="server" visible ="true"> <h3> testing </h3> </asp:panel>
code behind
scriptmanager.registerstartupscript(this, this.gettype(), "scriptblock", "document.getelementbyid('" + filterbanners.clientid + "') .style.display='none';", true);
edit 3
if want panel hidden , want show server not use server side property visible="false" instead use style="display:none;" in html.
html
<asp:panel id="filterbanners" runat="server" style="display:none;"> <h3> testing </h3> </asp:panel>
code behind
scriptmanager.registerstartupscript(this, this.gettype(), "scriptblock", "document.getelementbyid('" + filterbanners.clientid + "').style.display='block';", true);
Comments
Post a Comment