2011-08-02 49 views
0

我有一个带3个单选按钮和文本框的用户控件。如果选择RB1,我将显示文本框。对于剩余的两个选项,我将隐藏文本框。为单选按钮动态添加属性

<asp:RadioButton ID="rbAPL" runat="server" Checked="true" CssClass="tablecelldata" 
       GroupName="ServiceType" Text="Testing of Animal Pathogens & Veterinary Biologics" /><br /> 
    <asp:RadioButton ID="rbVPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType" 
       Text="Food Testing and Export Health Certification (Veterinary Health Certificate for Meat, Fish & Dairy Products)" /><br /> 
    <asp:RadioButton ID="rbPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType" 
       Text="Plant Health Diagnosis Services" /> 

然后将文本框

<asp:TextBox ID="tbxApplicationRefNo" runat="server" Width="350px"></asp:TextBox> 

我想动态设置单选按钮的属性来显示或隐藏文本框。我该怎么做?

在此先感谢您的回复!

+0

看起来像你想用javascript做的事情,而不是服务器端。 – Oded

+0

不客气!我会很高兴,如果你投票了我的答案:)谢谢。 – vladimir77

回答

0

1添加处理程序,以单选按钮

2对于显示/隐藏的JS-onclick事件(例如: “节目()$( '#ID');”)

3收费最初注意TextBox是不可见的cos RB1被屏蔽

<asp:RadioButton ID="rbAPL" runat="server" Checked="true" CssClass="tablecelldata" GroupName="ServiceType" Text="Testing of Animal Pathogens & Veterinary Biologics" onclick='<%# string.Format("$(&#39;#{0}&#39;).hide();", tbxApplicationRefNo.ClientID) %>' /> 
<br /> 
<asp:RadioButton ID="rbVPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType" Text="Food Testing and Export Health Certification (Veterinary Health Certificate for Meat, Fish & Dairy Products)" onclick='<%# string.Format("$(&#39;#{0}&#39;).show();", tbxApplicationRefNo.ClientID) %>' /> 
<br /> 
<asp:RadioButton ID="rbPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType" Text="Plant Health Diagnosis Services" onclick='<%# string.Format("$(&#39;#{0}&#39;).show();", tbxApplicationRefNo.ClientID) %>' /> 
<br /> 
<asp:TextBox style="display:none" ID="tbxApplicationRefNo" runat="server" Width="350px" Text="hello :)"></asp:TextBox> 
+0

谢谢vladimir77 –

0

我会做这样的事情在后面的代码:

public void rbAPL_CheckedChanged(object sender, EventArgs e) 
{ 
    RadioButton button = sender as RadioButton; 

    if (button.Checked) 
    { 
     tbxApplicationRefNo.Visible = true; 
    } 
} 

设置文本框为可见被点击时它。使用jquery