Click here to Skip to main content
15,915,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
first i have disabled textbox on page load, after clicking on radiobutton i want enable it and have to store clicked value of radio button in database
Posted
Comments
Nelek 9-Nov-12 2:55am    

disable text box in not ispostback and enable it in raidobutton check change event for that u have to set autopostback true of radiobutton and i suggest u to put it in updatepanel....
 
Share this answer
 
C#
public partial class RadioButton : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Enabled = false;
    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        TextBox1.Enabled = true;
        TextBox1.Text = "I Am Male";
        string value = RadioButton1.Text;
        SqlConnection sqlconn = new SqlConnection("server=.\\sqlexpress;database=practice;integrated security=true;");
        SqlCommand sqlcomm = new SqlCommand("insert into insertvalue(radiobtnvalue) values(@a)", sqlconn);
        sqlconn.Open();
        sqlcomm.Parameters.Add("@a", SqlDbType.VarChar, 10).Value = value.ToString();

        sqlcomm.ExecuteNonQuery();
        sqlconn.Close();
        Response.Write("Value Saved");
    }
}


Source-

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadioButton.aspx.cs" Inherits="RadioButton" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 87px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <table class="style1">
            <tr>
                <td class="style2">
                    Select Value</td>
                <td>
                    <asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack="True"
                        oncheckedchanged="RadioButton1_CheckedChanged" Text="Male" />
                </td>
            </tr>
            <tr>
                <td class="style2">
                    Name</td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>

    </div>
    </form>
</body>
</html>


Sql part-

SQL
create table insertvalue(radiobtnvalue varchar(10))
select * from insertvalue
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900