Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 25, 2012 09:44 AM by Ruchira
Member
67 Points
194 Posts
Jun 24, 2012 06:27 AM|LINK
anyone got idea about the radiobutton...
if the user choose No (disabled the textbox) if yes (they can type in the textbox)
anyone?
127 Points
83 Posts
Jun 24, 2012 06:32 AM|LINK
for this you can use one radio button and use the Checked property of that
if the checked property is true
then textbox will be enabled or read only or what ever you want to do
and if the checked property is false then u can enable or disable the textbox
Star
8976 Points
1659 Posts
Jun 24, 2012 06:41 AM|LINK
Hello, Paminchever!
Concentrate the Scenario I made an example,
you have YesRadioButton & NoRadioButton (Both AutoPostBack = true)
Its your HTML Markup for NoRadioButton
<asp:RadioButton ID="NoRadioButton" runat="server" Text="No" AutoPostBack="True" GroupName="SomethingSame" oncheckedchanged="NoRadioButton_CheckedChanged" />
We have oncheckedChanged Event,
Now, Codebehind Code
protected void NoRadioButton_CheckedChanged(object sender, EventArgs e) { if (NoRadioButton.Checked = true) { YourDesiredTextBox.Enabled = false; } }
Good luck`
GroupName="type"
Jun 24, 2012 06:48 AM|LINK
and 1 more way, you can use
without any Event of oncheckchanged
you can simply write aspx HTML Markup like
<asp:RadioButton ID="NoRadioButton" runat="server" Text="No" AutoPostBack="True" GroupName="SomethingSame" />
and write Code in your Codebehind "Page_Load" event
if (IsPostBack) { if (NoRadioButton.Checked = true) { YourDesiredTextBox.Enabled = false; } }
good luck`
Jun 24, 2012 06:51 AM|LINK
here is the comple code for that
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!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></title> </head> <body> <form id="form1" runat="server"> <div> <asp:RadioButton ID="RadioButton1" runat="server" oncheckedchanged="RadioButton1_CheckedChanged" AutoPostBack="True" GroupName="type" Text="yes" /> <br /> <br /> <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True" GroupName="type" oncheckedchanged="RadioButton2_CheckedChanged" Text="no" /> <br /> <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> </div> </form> </body> </html>
in code behind file
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void RadioButton1_CheckedChanged(object sender, EventArgs e) { if (RadioButton1.Checked == true) { TextBox1.Enabled = false; } } protected void RadioButton2_CheckedChanged(object sender, EventArgs e) { if (RadioButton2.Checked == true) { TextBox1.Enabled = true; } } }
Contributor
2948 Points
985 Posts
Jun 24, 2012 06:54 AM|LINK
use checked changed event of radio button control
protected
void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radiobutton1.checked==true)
textbox1.enable=true;
}
else
textbox1.enable=false;
Jun 24, 2012 06:59 AM|LINK
----------------------------------------
<body> <form id="form1" runat="server"> <div> <asp:RadioButton ID="RadioButton1" runat="server" oncheckedchanged="RadioButton1_CheckedChanged" AutoPostBack="True" GroupName="type" Text="yes" /> <br /> <br /> <asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True" GroupName="type" oncheckedchanged="RadioButton2_CheckedChanged" Text="no" /> <br /> <asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox> </div> </form> </body>
Jun 24, 2012 07:09 AM|LINK
i dont like to have a postback. because the page seems to be refresh. and i hate it. any idea?
Jun 24, 2012 07:24 AM|LINK
set autopostback property is true of radio button control without post a request to server how to possible that .
i think its not possible
Jun 24, 2012 08:49 AM|LINK
paminchever i dont like to have a postback. because the page seems to be refresh. and i hate it. any idea?
No no no,,, Post Back is not Mean that Page is Refreshing.. PostBack is a Method that Page Contact to the Server..
your Concept About Postback is wrong.. My 2 Post Which i give you Answer are Correct!
if you dont Want to show PostBack to the clientside.. Then use ScriptManager and UpdatePanel
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <!-- Radio Button HTML Markup --> <asp:RadioButton ID="NoRadioButton" runat="server" Text="No" AutoPostBack="True" GroupName="SomethingSame" /> </ContentTemplate> </asp:UpdatePanel>
then My whole Code of Codebehind
paminchever
Member
67 Points
194 Posts
radio button with textbox enabled and disabled
Jun 24, 2012 06:27 AM|LINK
anyone got idea about the radiobutton...
if the user choose No (disabled the textbox) if yes (they can type in the textbox)
anyone?
deepender
Member
127 Points
83 Posts
Re: radio button with textbox enabled and disabled
Jun 24, 2012 06:32 AM|LINK
for this you can use one radio button and use the Checked property of that
if the checked property is true
then textbox will be enabled or read only or what ever you want to do
and if the checked property is false then u can enable or disable the textbox
MahadTECH
Star
8976 Points
1659 Posts
Re: radio button with textbox enabled and disabled
Jun 24, 2012 06:41 AM|LINK
Hello, Paminchever!
Concentrate the Scenario I made an example,
you have YesRadioButton & NoRadioButton (Both AutoPostBack = true)
Its your HTML Markup for NoRadioButton
<asp:RadioButton ID="NoRadioButton" runat="server" Text="No" AutoPostBack="True" GroupName="SomethingSame" oncheckedchanged="NoRadioButton_CheckedChanged" />We have oncheckedChanged Event,
Now, Codebehind Code
protected void NoRadioButton_CheckedChanged(object sender, EventArgs e) { if (NoRadioButton.Checked = true) { YourDesiredTextBox.Enabled = false; } }Good luck`
GroupName="type"
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
MahadTECH
Star
8976 Points
1659 Posts
Re: radio button with textbox enabled and disabled
Jun 24, 2012 06:48 AM|LINK
and 1 more way, you can use
without any Event of oncheckchanged
you can simply write aspx HTML Markup like
and write Code in your Codebehind "Page_Load" event
if (IsPostBack) { if (NoRadioButton.Checked = true) { YourDesiredTextBox.Enabled = false; } }good luck`
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog
deepender
Member
127 Points
83 Posts
Re: radio button with textbox enabled and disabled
Jun 24, 2012 06:51 AM|LINK
here is the comple code for that
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server"
oncheckedchanged="RadioButton1_CheckedChanged" AutoPostBack="True"
GroupName="type" Text="yes" />
<br />
<br />
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"
GroupName="type" oncheckedchanged="RadioButton2_CheckedChanged" Text="no" />
<br />
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox>
</div>
</form>
</body>
</html>
in code behind file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton1.Checked == true)
{
TextBox1.Enabled = false;
}
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton2.Checked == true)
{
TextBox1.Enabled = true;
}
}
}
tarunSaini
Contributor
2948 Points
985 Posts
Re: radio button with textbox enabled and disabled
Jun 24, 2012 06:54 AM|LINK
use checked changed event of radio button control
protected
void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radiobutton1.checked==true)
{
textbox1.enable=true;
}
else
{
textbox1.enable=false;
}
}
deepender
Member
127 Points
83 Posts
Re: radio button with textbox enabled and disabled
Jun 24, 2012 06:59 AM|LINK
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton1.Checked == true)
{
TextBox1.Enabled = false;
}
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton2.Checked == true)
{
TextBox1.Enabled = true;
}
}
}
----------------------------------------
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButton ID="RadioButton1" runat="server"
oncheckedchanged="RadioButton1_CheckedChanged" AutoPostBack="True"
GroupName="type" Text="yes" />
<br />
<br />
<asp:RadioButton ID="RadioButton2" runat="server" AutoPostBack="True"
GroupName="type" oncheckedchanged="RadioButton2_CheckedChanged" Text="no" />
<br />
<asp:TextBox ID="TextBox1" runat="server">
</asp:TextBox>
</div>
</form>
</body>
paminchever
Member
67 Points
194 Posts
Re: radio button with textbox enabled and disabled
Jun 24, 2012 07:09 AM|LINK
i dont like to have a postback. because the page seems to be refresh. and i hate it. any idea?
tarunSaini
Contributor
2948 Points
985 Posts
Re: radio button with textbox enabled and disabled
Jun 24, 2012 07:24 AM|LINK
set autopostback property is true of radio button control without post a request to server how to possible that .
i think its not possible
MahadTECH
Star
8976 Points
1659 Posts
Re: radio button with textbox enabled and disabled
Jun 24, 2012 08:49 AM|LINK
No no no,,, Post Back is not Mean that Page is Refreshing.. PostBack is a Method that Page Contact to the Server..
your Concept About Postback is wrong.. My 2 Post Which i give you Answer are Correct!
if you dont Want to show PostBack to the clientside.. Then use ScriptManager and UpdatePanel
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <!-- Radio Button HTML Markup --> <asp:RadioButton ID="NoRadioButton" runat="server" Text="No" AutoPostBack="True" GroupName="SomethingSame" /> </ContentTemplate> </asp:UpdatePanel>then My whole Code of Codebehind
and write Code in your Codebehind "Page_Load" event
Good luck`
Mahad Bin Mukhtar
Remember to Mark the replies as Answers
The easiest day was 'yesterday'.
MCP, MCSD
For .NET TECH Blog