Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript in asp.net

<asp:RadioButtonList ID="RdoBtnHasNotified" runat="server" RepeatDirection="Horizontal" AutoPostBack="True" OnSelectedIndexChanged="RdoBtnHasNotified_SelectedIndexChanged">
    <asp:ListItem Value="1">Yes</asp:ListItem>
    <asp:ListItem Value="0" Selected="True">No</asp:ListItem>
</asp:RadioButtonList>


<asp:TextBox ID="TxtHowNotified" runat="server" TextMode="MultiLine" MaxLength="100"></asp:TextBox>

I want to enable the TextBox by clicking on the RadioButtonList, without using autopostback=true. How can I do this with JavaScript?

like image 239
user354488 Avatar asked May 31 '10 11:05

user354488


2 Answers

You can use jQuery to manipulate input's enabled state (HTML translation for TextBox) or you can use ASP.NET Ajax so you can set both controls inside of update panel in this case you won't see page being reloaded on postback which must happen in order for you to change status of TextBox on some other event. Tbh i would go with ASP.NET Ajax because my experience shows that jQuery does not work that well with ASP.NET controls when it comes to complex stuff ie. ASP.NET uses javascript for event activation which can cause either jQuery or ASP.NET not to work as you may expected.

Good luck with update panels...

like image 67
eugeneK Avatar answered Oct 30 '22 05:10

eugeneK


Using jQuery, you can have a fairly custom result by hooking in to the changes on the radio buttons...


$("#<%= RdoBtnHasNotified.ClientID %> > input[type=radio]").change(function(){
  // this function is called whenever one of the radio button list's control's change
  // the $(this) variable refers to the input control that triggered the event
  var txt = $("#<%= TxtHowNotified.ClientID %>");
  if($(this).val()=="1") {
    txt.removeAttr("disabled");
  } else {
    txt.attr("disabled", true);
  }
});
like image 29
ilowe Avatar answered Oct 30 '22 05:10

ilowe