[英]Dynamically add attribute for radiobutton
I have a usercontrol with 3 radiobuttons and textbox. 我有一个带有3个单选按钮和文本框的用户控件。 If RB1 is selected, I will display the textbox.
如果选择了RB1,我将显示文本框。 For the remaining two options, I will hide the textbox.
对于其余两个选项,我将隐藏文本框。
<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" />
And the textbox 和文本框
<asp:TextBox ID="tbxApplicationRefNo" runat="server" Width="350px"></asp:TextBox>
I want to dynamically set the attributes of radiobuttons to show or hide the textbox. 我想动态设置单选按钮的属性以显示或隐藏文本框。 How can I do so?
我该怎么办?
Thanks in advance for your reply! 预先感谢您的答复!
I would do something like this in the code behind: 我会在后面的代码中执行以下操作:
public void rbAPL_CheckedChanged(object sender, EventArgs e)
{
RadioButton button = sender as RadioButton;
if (button.Checked)
{
tbxApplicationRefNo.Visible = true;
}
}
Set the Textbox as Visible when it is clicked. 单击时将“文本框”设置为“可见”。
1 Add handler to js-onclick event of radiobutton 1将处理程序添加到单选按钮的js-onclick事件
2 For show/hide using jquery (for example: "$('#id').show();") 2使用jquery进行显示/隐藏(例如:“ $('#id')。show();”)
3 Pay attention initially TextBox is invisible cos RB1 is cheked 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("$('#{0}').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("$('#{0}').show();", tbxApplicationRefNo.ClientID) %>' />
<br />
<asp:RadioButton ID="rbPHL" runat="server" CssClass="tablecelldata" GroupName="ServiceType" Text="Plant Health Diagnosis Services" onclick='<%# string.Format("$('#{0}').show();", tbxApplicationRefNo.ClientID) %>' />
<br />
<asp:TextBox style="display:none" ID="tbxApplicationRefNo" runat="server" Width="350px" Text="hello :)"></asp:TextBox>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.