Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am use 2 radio button name club and individual if club is checked show a text box if individual is checked not show the text box
Posted

use this document.getElementById('controlid').style.display='none';
to hide
and to unhide use this
document.getElementById('controlid').style.display='block';
 
Share this answer
 
In .aspx page

<asp:radiobuttonlist id="rbl" runat="server" onselectedindexchanged="rbl_OnSelectedIndexChanged" autopostback="true">
<asp:listitem text="Club" selected="True">
<asp:listitem text="Individual">

<asp:textbox id="txtC" runat="server" text="Club">
<asp:textbox id="txtI" runat="server" text="Individual">

---------------------------------------------------------------------------
In .aspx.cs page

protected void Page_Load(object sender, EventArgs e)
{
txtI.Visible = false;
txtC.Visible = false;
}
protected void rbl_OnSelectedIndexChanged(object sender, EventArgs e)
{
if (rbl.SelectedItem.Text == "Club")
{
txtI.Visible = false;
txtC.Visible = true;
}
else if (rbl.SelectedItem.Text == "Individual")
{
txtC.Visible = false;
txtI.Visible = true;
}
}


Hope this will solve your problem,
@Nidhish
 
Share this answer
 
v2
Comments
pucit009 1-Jun-11 5:49am    
please give me a java script
RakeshMeena 1-Jun-11 5:51am    
Why to postback just to show/hide a control (textbox here)? Javascript would do it...
Try below solution using JQuery: You need to add JQuery file to your solution.


<script type="text/javascript" src="jquery-1.6.js"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("input:radio").click(function() {
if ((this).value == 1) {
$("#txt").hide();
} else if ((this).value == 2) {
$("#txt").show();
}
});
});
</script>
</head>
<body >
<form id="form1" runat="server">
<asp:RadioButtonList ID="rbtnList" runat="server">
<asp:ListItem Text="Club" Value="1"></asp:ListItem>
<asp:ListItem Text="Individual" Value="2"></asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="txt" runat="server" />
</form>
</body>
</html>
 
Share this answer
 
Using Javascript,

In .aspx page,

<head runat="server">
<script language="javascript" type="text/javascript">
function rblSelect()
{
var a = null;
var f = document.forms[0];
var e = f.elements["rbl"];
for (var i=0; i < e.length; i++)
{
if (e[i].checked)
{
a = e[i].value;
break;
}
}
if(a=="Club")

{
document.getElementById('<%=txtC.ClientID %>').style.visibility='visible';
document.getElementById('<%=txtI.ClientID %>').style.visibility='hidden';
}
else if(a=="Individual")
{
document.getElementById('<%=txtC.ClientID %>').style.visibility='hidden';
document.getElementById('<%=txtI.ClientID %>').style.visibility='visible';
}
}
</script>
</head>
<body önload="rblSelect()">
<form id="form1" runat="server">
....
....
<asp:radiobuttonlist id="rbl" runat="server" onclick="rblSelect()">
<asp:listitem text="Club" selected="True">
<asp:listitem text="Individual">



<asp:textbox id="txtC" runat="server" text="Club">
<asp:textbox id="txtI" runat="server" text="Individual">

...........
...........
</form></body>

..........
@Nidhish
 
Share this answer
 
v3

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