2011-08-02 86 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