Saturday, 4 August 2012

ASP.NET Disable TextBox using Javascript.

I've Briefly Answered:  http://forums.asp.net/post/5038180.aspx
Task : the goal was to disable asp:Textbox on asp:Radiobutton Check/uncheck. ( without PostBack we know with Codebehind its easy..)


So,

Javascript Code write under <head> Section
    <script type="text/javascript">
       function Radio() {
        var No = document.getElementById('<%= NoRadioButton.ClientID %>').checked;
        var Yes = document.getElementById('<%= YesRadioButton.ClientID %>').checked;
        if (No == true)
            {
                document.getElementById('<%= YourTextBoxID.ClientID %>').disabled = true;
            }
         if (Yes == true)
            {
                document.getElementById('<%= YourTextBoxID.ClientID %>').disabled = false;
            }
        }
        
    </script>
and your Page aspx. HTML Markup of Radio Button!
        <asp:RadioButton ID="YesRadioButton" runat="server" GroupName="Same" Text="Yes" onClick="Radio()" />
        <asp:RadioButton ID="NoRadioButton" runat="server" GroupName="Same" Text="No" onClick="Radio()" />
Good luck`

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More