jquery asp.net button visibility

9.8k views Asked by At

There is some code like this :

if ( bValid ) { 
      $( this ).dialog( "close" );
$("#btnExcel").show(); }

and .aspx look like :

  <form id="form1" runat="server">
                    <input id="inpHide" type="hidden" runat="server" />
                    <asp:Button ID="btnExcel" runat="server" Text="Excel" AccessKey="E" BorderWidth="0px"
                        OnClick="btnExcel_Click" ToolTip="Excel" Visible="false" />
                    </form>

`bValid` is some part of code

Why this doesnt work ? What can be done to work it out. To make button visisble ?

may be its not accessible because :

var button = $('#btnExcel')[0]; 
                        alert(button);

shows : undefined !

Looking for help.

4

There are 4 answers

2
Shiv Kumar On BEST ANSWER

You can't have the button as Visible="false" on the server side. That is in your ASPX page you need to have it Visible="true" because otherwise the button is not rendered to html.

You could set the style attirbute (or CssStyle attirbute) on your button to style="display:none;" and then things will work

<asp:Button ID="btnExcel" runat="server" Text="Excel" AccessKey="E" BorderWidth="0px"
                        OnClick="btnExcel_Click" ToolTip="Excel" Visible="true" style="display:none;" />
0
Collin O'Connor On

Can you set the button's display to none?

1
Arun On

Thats because the IDs of server controls generated by ASP.Net is different in the browser. View the HTML source in the browser, find the correct control ID and use that in the jQuery code. You can also try ClientID function of ASP.Net

See this for more: http://forums.asp.net/p/1522697/3664258.aspx

1
Madhur Ahuja On

btnExcel will be mangled since its a server side control.

Obtain the mangled id as document.getElementByid(<%=btnExcel.ClientID%>)