使表可见单击按钮

时间:2016-02-27 17:28:37

标签: asp.net

Table2是不可见的,我想在点击Register Button时显示它。

<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";
    }

获取错误

  

Table2在当前上下文中不存在。

1 个答案:

答案 0 :(得分:2)

您需要在表格中设置runat属性才能使其正常工作

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

更改按钮点击事件

Table2.style.visibility="visible";

Table2.Visible = true; // to show

并在页面加载事件中使用

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