connectseekers.com

Friday, 17 February 2017

Enable Disable Textbox Using Jascript Radio Button Click

2/17/2017 - By Pranav Singh 0

This article will show you how you can enable disable textbox using jascript radio button click in asp.net radbutton.

So for this article first we will create a new asp.net application and add some radiobutton and a textbox control on page. After adding controls your code will look as shown below.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RedioButton.aspx.cs" Inherits="Shoping_Cart.RedioButton" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Enable Disable Textbox Using Jascript Radio Button Click</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <asp:TextBox ID="TextBox1" runat="server" Width="228px"></asp:TextBox>
            <br />
            <br />
            <asp:RadioButton ID="rbtEnable" runat="server" Text="Enable" />
            <asp:RadioButton ID="rbtDisable" runat="server" Text="Disable" />
        </div>
    </form>
</body>
</html>

Now let’s write code for enabling and disabling the textbox.

function EnableDisableTextBox() {
            var status = document.getElementById('<%=rbtEnable.ClientID %>').checked;
            if (status == true) {
                document.getElementById('<%=TextBox1.ClientID %>').disabled = false;
            } else {
                document.getElementById('<%=TextBox1.ClientID %>').disabled = true;
            }
        }

In above code I have get the checked status of the radio button and then on status I have enable disable the textbox on click on radio button selection.

Here is the complete code.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RedioButton.aspx.cs" Inherits="Shoping_Cart.RedioButton" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Enable Disable Textbox Using Jascript Radio Button Click</title>
    <script type="text/javascript">
        function EnableDisableTextBox() {
            var status = document.getElementById('<%=rbtEnable.ClientID %>').checked;
            if (status == true) {
                document.getElementById('<%=TextBox1.ClientID %>').disabled = false;
            } else {
                document.getElementById('<%=TextBox1.ClientID %>').disabled = true;
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <asp:TextBox ID="TextBox1" runat="server" Width="228px"></asp:TextBox>
            <br />
            <br />
            <asp:RadioButton ID="rbtEnable" runat="server" Text="Enable" onclick="javascript:EnableDisableTextBox();" GroupName="1" />
            <asp:RadioButton ID="rbtDisable" runat="server" Text="Disable" onclick="javascript:EnableDisableTextBox();" GroupName="1" />
        </div>
    </form>
</body>
</html>


I have called the JavaScript code on radio button click event. Now we have done run the application to check the output.


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Design By:
back to top