2016-02-27 192 views
2

表格2是不可见的,我想让它在点击注册按钮时可见。制作表格可见点击按钮

<table> 
    <tr> 
     <td> 
      <asp:Button Id="btnstudent" runat="server" Text="Student Registraion" OnClick="btnstudent_Click"/> 
     </td> 
     <td> 
      <asp:Button ID="btnfees" runat="server" Text="Fees"/> 
     </td> 

    </tr> 

</table> 

<table ID="Table2" style="visibility:hidden"> 
    <tr> 
     <td> 
      Name 
     </td> 
     <td> <asp:TextBox ID="nametxt" runat="server"></asp:TextBox></td> 
    </tr> 
    <tr> 
     <td> 
      Contact No. 
     </td> 
     <td> <asp:TextBox ID="contacttxt" runat="server"></asp:TextBox></td> 
    </tr> 
    <tr> 
     <td> 
      Course Name 
     </td> 
     <td> <asp:TextBox ID="coursetxt" runat="server"></asp:TextBox></td> 
    </tr> 
    <tr> 
     <td> 
      Fees 
     </td> 
     <td> <asp:TextBox ID="feetxt" runat="server"></asp:TextBox></td> 
    </tr> 
    <tr> 
     <td> 
      Address 
     </td> 
     <td> <asp:TextBox ID="Addresstxt" runat="server"></asp:TextBox></td> 
    </tr><tr> 
     <td> 
      <asp:Button ID="btnregister" runat="server" Text="Register"/> 
     </td> 

     </tr> 

</table> 
</asp:Content> 

//On button Click 

protected void btnstudent_Click(object sender, EventArgs e) 
    { 
     Table2.style.visibility="visible"; 
    } 

得到错误

表2并不在目前的情况下存在。

+0

格式化代码的最后一部分('btnstudent_Click'函数的定义)和错误日志。 –

回答

2

您需要设置RUNAT属性在表中,以使其工作

<table id="Table2" runat="server"> 

更改您的按钮单击事件

Table2.style.visibility="visible"; 

Table2.Visible = true; // to show 

和在你的页面加载事件中使用

if (!IsPostBack) 
{ 
Table2.Visible = false; // to hide 
}