表格行ID在后面的代码中无法访问 [英] table row id not accessible at code behind

查看:110
本文介绍了表格行ID在后面的代码中无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于填写详细信息的表单,在此表单中,我有一个单选按钮...在selectedindexchange上,如果value为No则什么都不发生,如果value为Yes,那么我想向用户显示一个小表格(name2) .

I have one form for filling details and in this form i have one radio button...On selectedindexchange, if value is No then nothing happen and if value is Yes then i want to show a small form(name2) to user.

<table>
<tr>
<td>
Are you known by any other names or aliases?*: 
<asp:RadioButtonList ID="RadioButtonList1" runat="server"    RepeatDirection="Horizontal"                          onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No" Selected="True">No</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr id="name2" style="visibility:hidden">
<td>
Other names or aliases?*: 
<asp:TextBox ID="TextBox3" CssClass="textboxhalf" runat="server"></asp:TextBox>
</td>
</tr>
</table>


protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedValue == "1")
        {
            TextBox3.Visible = true;
        }
        else
        {
            
            TextBox3.Visible = false;
        }
    }


在后面的代码中,我能够访问此textbox3 ...因此我可以使其可见或隐藏,但我无法访问表行id(name2).我想显示/隐藏ID为name2的整个表格行.


In code behind i able to access this textbox3...so i can make it visible or hide but i cannot access table row id(name2). I want to show/hide whole table row with id name2. Is that possible by only C#?

推荐答案

您缺少runat ="server"属性.
这将告诉ASP.NET为该元素创建服务器端对象.没有它的元素只能从客户端访问...
You missing the the runat="server" attribute.
That will tell ASP.NET to create a server side object for that element. Elements without it will be accessible only from the client...
<table><tbody><tr id="name2" style="visibility:hidden" runat="server"></tr></tbody></table>


这篇关于表格行ID在后面的代码中无法访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆