Codeaddict7423
asked on
passing values through checkbox
how do i pass a valuethrough a checkbox
Where ho you want to pass values through checkbox?
On click of checkbox, do you want to enable javascript or do some processing on server?
On click of checkbox, do you want to enable javascript or do some processing on server?
Please explain better your question
ASKER
thank you. i'm getting a better definition of the goal for the checkboxes now and i'll ask again later.
ASKER
hello,
i have a better understanding now. how do i pass a value from a checkbox when the user checks a checkbox?
i have a better understanding now. how do i pass a value from a checkbox when the user checks a checkbox?
<input type="checkbox" name="mycb" value="myvalue"
if checked variable "mycb" will have value "myvalue"
is it u want?
if checked variable "mycb" will have value "myvalue"
is it u want?
<input type="checkbox" name="mycb" value="myvalue"> **
ASKER
i tried the input idea and it did not pass the value. i have this
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" Text="April 23, 2010 Test" />
how do i pass the value "April 23, 2010" directly from this check box so that the checkbox is identified wome way other than "checkbox1" and has a value of a text string?
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" Text="April 23, 2010 Test" />
how do i pass the value "April 23, 2010" directly from this check box so that the checkbox is identified wome way other than "checkbox1" and has a value of a text string?
The best way is to put code in the checked changed event.
Then you can verify the checked property, for example:
private void myCheckBox_CheckedChanged( object sender, EventArgs e)
{
if(myCheckBox.Checked)
//do something
}
Then you can verify the checked property, for example:
private void myCheckBox_CheckedChanged(
{
if(myCheckBox.Checked)
//do something
}
ASKER
great, i'm using vb.net, can you please provide sample code to make the asp:checkbox control have an id other than checkbox1 and pass a value of a text string?
To get Checkbox's text in code behind file use
string strChkBoxText = CheckBox1.Text;
To get Checkbox's text in javascript refer
http://blog-dotnetsp.blogspot.com/2010/01/get-checkbox-text-and-checked-property.html
string strChkBoxText = CheckBox1.Text;
To get Checkbox's text in javascript refer
http://blog-dotnetsp.blogspot.com/2010/01/get-checkbox-text-and-checked-property.html
ASKER
rajapandian_81:
Thank you. can you please help with the javascript code to do this?
Thank you. can you please help with the javascript code to do this?
Codeaddict7423,
Whenever you click the checkbox, javascript will alert the checkbox's text. Is that you are looking for?
Whenever you click the checkbox, javascript will alert the checkbox's text. Is that you are looking for?
function checkboxClick(obj)
{
var lbl = obj.nextSibling;
while(lbl.nodeName.toLowerCase()!='label')
lbl=lbl.nextSibling;
alert(lbl.innerHTML);
}
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" Text="April 23, 2010 Test" onclick="checkboxClick(this);" />
ASKER
rajapandian_81:
Thank you, i tried your suggestion and the return result is "CheckBox1" = True. How can assign an ID to CheckBox1 or rename it to something like "Date of Workshop" and have a text string attached to it so that it returns a value like "April 23" ? i'm really pressured to fix this... please help.
Thank you, i tried your suggestion and the return result is "CheckBox1" = True. How can assign an ID to CheckBox1 or rename it to something like "Date of Workshop" and have a text string attached to it so that it returns a value like "April 23" ? i'm really pressured to fix this... please help.
I can't understand your question. Please clarify your needs.
ASKER
rajapandian_81:
Thanks for replying. I'm really under pressure here. Im using VB.NET in a user control. in that user control there is a checkbox next to the description of an event scheduled for April 23, 2010.
i have a asp: checkbox "<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" Text="April 23, 2010 Test" onclick="checkboxClick(thi s);" /> "
I'm trying to get this checkbox , when checked, to return a value something other thann "checkbox1" and a text string of "April 23, 2010"
i'm open to using javascript or vb.net code...any sample code that works is great....
Please, pleae help
Thanks for replying. I'm really under pressure here. Im using VB.NET in a user control. in that user control there is a checkbox next to the description of an event scheduled for April 23, 2010.
i have a asp: checkbox "<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" Text="April 23, 2010 Test" onclick="checkboxClick(thi
I'm trying to get this checkbox , when checked, to return a value something other thann "checkbox1" and a text string of "April 23, 2010"
i'm open to using javascript or vb.net code...any sample code that works is great....
Please, pleae help
So you need some string like 'Date of Workshop' and the text of checkbox when it is checked.
Try below javascript. I will post vb.net code also.
Try below javascript. I will post vb.net code also.
function checkboxClick(obj)
{
if (obj.checked)
{
var lbl = obj.nextSibling;
while(lbl.nodeName.toLowerCase()!='label')
lbl=lbl.nextSibling;
alert('Date of Workshop ' + lbl.innerHTML);
}
}
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" Text="April 23, 2010" onclick="checkboxClick(this);" />
ASKER
rajapandian_81:
Thank yoiu. will this javascript code pass the value of the checkbox? I'm trying to get the checkbox name (something like "Date of Workshop") to pass a value or a string like "April 23, 2010" directly maby this van be passed on to a hidden field?
Please help...
Thank yoiu. will this javascript code pass the value of the checkbox? I'm trying to get the checkbox name (something like "Date of Workshop") to pass a value or a string like "April 23, 2010" directly maby this van be passed on to a hidden field?
Please help...
Hey Jason,
Did you come across this in your research? http://forums.asp.net/t/769696.aspx Seems like this guy figured it out.
Hope this helps,
Elliot
Did you come across this in your research? http://forums.asp.net/t/769696.aspx Seems like this guy figured it out.
Hope this helps,
Elliot
ASKER
nomoose:
i'm sorry i did not see a solution to my question.
this is what i'm trying to do:
I'm using VB.NET in a user control. in that user control there is a checkbox next to the description of an event scheduled for April 23, 2010.
i have a asp: checkbox "<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" Text="April 23, 2010 Test" onclick="checkboxClick(thi s);" /> "
I'm trying to get this checkbox , when checked, to return a value something other thann "checkbox1" and a text string of "April 23, 2010"
i'm open to using javascript or vb.net code...any sample code that works is great....
Please, help
i'm sorry i did not see a solution to my question.
this is what i'm trying to do:
I'm using VB.NET in a user control. in that user control there is a checkbox next to the description of an event scheduled for April 23, 2010.
i have a asp: checkbox "<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="false" Text="April 23, 2010 Test" onclick="checkboxClick(thi
I'm trying to get this checkbox , when checked, to return a value something other thann "checkbox1" and a text string of "April 23, 2010"
i'm open to using javascript or vb.net code...any sample code that works is great....
Please, help
You can store the checkbox's id and text in hidden field and use it in server side.
function checkboxClick(obj)
{
if (obj.checked)
{
var lbl = obj.nextSibling;
while(lbl.nodeName.toLowerCase()!='label')
lbl=lbl.nextSibling;
document.getElementById('<%= hdn.ClientID %>').value = obj.id + ' ' + lbl.innerHTML;
}
}
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="false" Text="April 23, 2010" onclick="checkboxClick(this);" />
<input type="hidden" runat="server" id="hdn" />
ASKER
rajapandian_81:
thank you for the reply
when i implemented your solution, i got this:
-----------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'hdn' is not declared.
Source Error:
Line 89: while(lbl.nodeName.toLower Case()!='l abel')
Line 90: lbl=lbl.nextSibling;
Line 91: document.getElementById('< %= hdn.ClientID %>').value = obj.id + ' ' + lbl.innerHTML;
Line 92: }
Line 93: }
--------------
how do i declare "hdn"?
thanks,
thank you for the reply
when i implemented your solution, i got this:
-----------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'hdn' is not declared.
Source Error:
Line 89: while(lbl.nodeName.toLower
Line 90: lbl=lbl.nextSibling;
Line 91: document.getElementById('<
Line 92: }
Line 93: }
--------------
how do i declare "hdn"?
thanks,
In Comment #29217725 I added one hidden control like
<input type="hidden" runat="server" id="hdn" />
<input type="hidden" runat="server" id="hdn" />
ASKER
rajapandian_81:
Thanks for the quick reply. Yes, i saw that and included it in my code. i have the Javascript as:
<script type="text/javascript" language="javascript">
function checkboxClick(obj)
{
if (obj.checked)
{
var lbl = obj.nextSibling;
while(lbl.nodeName.toLower Case()!='l abel')
lbl=lbl.nextSibling;
document.getElementById('< %= hdn.ClientID %>').value = obj.id + ' ' + lbl.innerHTML;
}
}
</script>
and the checkbox code as follows:
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="false" Text="April 23, 2010" onclick="checkboxClick(thi s);" />
<input type="hidden" runat="server" id="hdn" />
what did i do wrong?
Thanks for the quick reply. Yes, i saw that and included it in my code. i have the Javascript as:
<script type="text/javascript" language="javascript">
function checkboxClick(obj)
{
if (obj.checked)
{
var lbl = obj.nextSibling;
while(lbl.nodeName.toLower
lbl=lbl.nextSibling;
document.getElementById('<
}
}
</script>
and the checkbox code as follows:
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="false" Text="April 23, 2010" onclick="checkboxClick(thi
<input type="hidden" runat="server" id="hdn" />
what did i do wrong?
Which version of visual studio you are using?
Are you getting the same error?
Are you getting the same error?
ASKER
rajapandian_81:
I'm using Visual Studio 2005
I'm trying to declare "hdn" in the Javascript so the script would run but am not havingany luck.
I get this error at runtime:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'hdn' is not declared.
Source Error:
Line 51: while(lbl.nodeName.toLower Case()!='l abel')
Line 52: lbl=lbl.nextSibling;
Line 53: document.getElementById('< %= hdn.ClientID %>').value = obj.id + ' ' + lbl.innerHTML;
Line 54: }
Line 55: }
I'm using Visual Studio 2005
I'm trying to declare "hdn" in the Javascript so the script would run but am not havingany luck.
I get this error at runtime:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'hdn' is not declared.
Source Error:
Line 51: while(lbl.nodeName.toLower
Line 52: lbl=lbl.nextSibling;
Line 53: document.getElementById('<
Line 54: }
Line 55: }
Delete the line
<input type="hidden" runat="server" id="hdn" />
and add HiddenField from ToolBox. Then change the id to hdn
<input type="hidden" runat="server" id="hdn" />
and add HiddenField from ToolBox. Then change the id to hdn
ASKER
rajapandian_81:
i'm still getting the same error;
this is what i put in:
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="false" Text="April 23, 2010" onclick="checkboxClick(thi s);" />
<input id="hdn" type="hidden" runat="server" />
-----------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'hdn' is not declared.
Source Error:
Line 53: while(lbl.nodeName.toLower Case()!='l abel')
Line 54: lbl=lbl.nextSibling;
Line 55: document.getElementById('< %= hdn.ClientID %>').value = obj.id + ' ' + lbl.innerHTML;
Line 56: }
Line 57: }
i'm still getting the same error;
this is what i put in:
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="false" Text="April 23, 2010" onclick="checkboxClick(thi
<input id="hdn" type="hidden" runat="server" />
-----------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'hdn' is not declared.
Source Error:
Line 53: while(lbl.nodeName.toLower
Line 54: lbl=lbl.nextSibling;
Line 55: document.getElementById('<
Line 56: }
Line 57: }
ASKER
rajapandian_81:
The error seems to be coming from the Javascript area and i was trying to declare "hdn" as var hdn=" ";
The error seems to be coming from the Javascript area and i was trying to declare "hdn" as var hdn=" ";
ASKER
rajapandian_81:
The error is specific to this line:
Line 55: document.getElementById('< %= hdn.ClientID %>').value = obj.id + ' ' + lbl.innerHTML;
please please help!
The error is specific to this line:
Line 55: document.getElementById('<
please please help!
Codeaddict7423:
As mentioned in Comment #29221471, remove the line
<input type="hidden" runat="server" id="hdn" />
Then try to add HiddenField control from ToolBox. Then change the id to hdn
As mentioned in Comment #29221471, remove the line
<input type="hidden" runat="server" id="hdn" />
Then try to add HiddenField control from ToolBox. Then change the id to hdn
ASKER
rajapandian_81:
Thanks for the quck reply, i did as you suggested, deleted the <input type hidden field and then readded a new field as follows:
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="false" Text="April 23, 2010" onclick="checkboxClick(thi s);" />
<input id="hdn" type="hidden" runat="server" />
however, i 'm still getting this:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'hdn' is not declared.
Source Error:
Line 53: while(lbl.nodeName.toLower Case()!='l abel')
Line 54: lbl=lbl.nextSibling;
Line 55: document.getElementById('< %= hdn.ClientID %>').value = obj.id + ' ' + lbl.innerHTML;
Line 56: }
Line 57:
i'm desperate for a solution...please help!
Thanks for the quck reply, i did as you suggested, deleted the <input type hidden field and then readded a new field as follows:
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="false" Text="April 23, 2010" onclick="checkboxClick(thi
<input id="hdn" type="hidden" runat="server" />
however, i 'm still getting this:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'hdn' is not declared.
Source Error:
Line 53: while(lbl.nodeName.toLower
Line 54: lbl=lbl.nextSibling;
Line 55: document.getElementById('<
Line 56: }
Line 57:
i'm desperate for a solution...please help!
I think you misunderstood.
I told to add the control from toolbox. You can drag and drop the control from toolbox. Refer below screenshot.
ToolBox.PNG
I told to add the control from toolbox. You can drag and drop the control from toolbox. Refer below screenshot.
ToolBox.PNG
So that new control will be added like
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:HiddenField ID="HiddenField1" runat="server" />
So final code will be
function checkboxClick(obj)
{
if (obj.checked)
{
var lbl = obj.nextSibling;
while(lbl.nodeName.toLowerCase()!='label')
lbl=lbl.nextSibling;
document.getElementById('<%= HiddenField1.ClientID %>').value = obj.id + ' ' + lbl.innerHTML;
}
}
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="false" Text="April 23, 2010" onclick="checkboxClick(this);" />
<asp:HiddenField ID="HiddenField1" runat="server" />
vb.net code:
Set the AutoPostBack as true for checkbox. Then CheckedChanged code will be
Set the AutoPostBack as true for checkbox. Then CheckedChanged code will be
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If (CheckBox1.Checked) Then
SomeFunction(CheckBox1.ID + " " + CheckBox1.Text)
End If
End Sub
Sub SomeFunction(ByVal strText As String)
//Here write steps you needed
End Sub
ASKER
rajapandian_81:
Thank you for your s uggestion.
Attached, please see a combined screenshot of what i see on my screen.
The "Handles CheckBox1.CheckedChanged" is giving me an error indication in Visual Studio in VB.NET
Please help
checkboxes-01.jpg
Thank you for your s uggestion.
Attached, please see a combined screenshot of what i see on my screen.
The "Handles CheckBox1.CheckedChanged" is giving me an error indication in Visual Studio in VB.NET
Please help
checkboxes-01.jpg
What error it shows?
Its working fine for me.
Its working fine for me.
ASKER
rajapandian_81:
thanks for the quick reply. in visual Studio, the sub called:
Protected Sub CheckBox1_CheckedChanged(B yVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
the line that starts wtih : Handles CheckBox1.CheckedChanged
is displayed with a squigly blue line under the word "CheckBox1" and throws an error on run
thanks for the quick reply. in visual Studio, the sub called:
Protected Sub CheckBox1_CheckedChanged(B
the line that starts wtih : Handles CheckBox1.CheckedChanged
is displayed with a squigly blue line under the word "CheckBox1" and throws an error on run
Is your both screenshot taken from user control page?
ASKER
rajapandian_81:
yes, absolutely from the user control screen
yes, absolutely from the user control screen
In top can you see CheckBox1 and CheckedChanged as shown in image below
CheckBox.PNG
CheckBox.PNG
ASKER
I just changed the dropdown controls to "checkbox1" and "checkedchanged" appears on the other control. i still get the wavy line, how do i change that?
Its working fine for me.
I am not able to figure out the problem in your application.
I am not able to figure out the problem in your application.
Can you create a sample application to reproduce error and attach here as a zip file.
ASKER
rajapandian_81:
thank yoiu for your help and time. maybe if i step back and explain what i'm being asked to do you can see.
I have a user control with an asp:checkbox next to a description of a workshop. i'm being asked to program the checkbox so that when a user checks the checkbox, a field (perahps a hidden field) gets populated wtih a string like "April 23, 2010" and returns that string value along with a checkbox name of something like "Workshop One" I'm being told this is a simple program and i'm banging my head against the wall.
If you and your colleagues can discuss this and help me with a solution, you'd save my day and more...
Thanks,
thank yoiu for your help and time. maybe if i step back and explain what i'm being asked to do you can see.
I have a user control with an asp:checkbox next to a description of a workshop. i'm being asked to program the checkbox so that when a user checks the checkbox, a field (perahps a hidden field) gets populated wtih a string like "April 23, 2010" and returns that string value along with a checkbox name of something like "Workshop One" I'm being told this is a simple program and i'm banging my head against the wall.
If you and your colleagues can discuss this and help me with a solution, you'd save my day and more...
Thanks,
Codeaddict7423:
I am not able to attach application, so I give the code here.
Code for Default.aspx
-------------------------- --------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register src="WebUserControl.ascx" tagname="UserControl2" tagprefix="uc1" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:UserControl2 ID="UserControl21" runat="server" />
</div>
</form>
</body>
</html>
Code for usercontrol ( WebUserControl.ascx)
-------------------------- ---------- ---------- ---------- -------
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl.a scx.vb" Inherits="WebUserControl" %>
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="true" Text="April 23, 2010" OnCheckedChanged="Date_of_ Workshop_C heckedChan ged" />
Code for WebUserControl.ascx.vb
-------------------------- ---------- ---------- --
Partial Class WebUserControl
Inherits System.Web.UI.UserControl
Protected Sub Date_of_Workshop_CheckedCh anged(ByVa l sender As Object, ByVal e As System.EventArgs) Handles Date_of_Workshop.CheckedCh anged
If (Date_of_Workshop.Checked) Then
SomeFunction(Date_of_Works hop.ID + " " + Date_of_Workshop.Text)
End If
End Sub
Sub SomeFunction(ByVal strText As String)
End Sub
End Class
I am not able to attach application, so I give the code here.
Code for Default.aspx
--------------------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register src="WebUserControl.ascx" tagname="UserControl2" tagprefix="uc1" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:UserControl2 ID="UserControl21" runat="server" />
</div>
</form>
</body>
</html>
Code for usercontrol ( WebUserControl.ascx)
--------------------------
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="WebUserControl.a
<asp:CheckBox ID="Date_of_Workshop" runat="server" AutoPostBack="true" Text="April 23, 2010" OnCheckedChanged="Date_of_
Code for WebUserControl.ascx.vb
--------------------------
Partial Class WebUserControl
Inherits System.Web.UI.UserControl
Protected Sub Date_of_Workshop_CheckedCh
If (Date_of_Workshop.Checked)
SomeFunction(Date_of_Works
End If
End Sub
Sub SomeFunction(ByVal strText As String)
End Sub
End Class
ASKER
rajapandian_81:
Sir,
Below, please find a code that seems to function but i'd like your opinion.
vbcode:
<script runat="server">
Protected Sub CheckBox1_CheckedChanged(B yVal sender As Object, ByVal e As System.EventArgs)
Dim Workshop_One_Date As CheckBox = CType(RSVPForm1.FindContro l("Worksho p_One_Date "), CheckBox)
Dim Date_of_First_Workshop As TextBox = CType(RSVPForm1.FindContro l("Date_of _First_Wor kshop"), TextBox)
Date_of_First_Workshop.Vis ible = "false"
If Workshop_One_Date.Checked = True Then
Date_of_First_Workshop.Tex t = "April 23, 2010"
Date_of_First_Workshop.Vis ible = "false"
Else
Date_of_First_Workshop.Tex t = ""
End If
End Sub
</script>
------------
code that calls the checkbox
<table cellpadding="0" cellspacing="0" style="border-color:gray" border="0">
<tr>
<td>
<asp:CheckBox ID="Workshop_One_Date" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox 1_CheckedC hanged" />
</td>
<td>
<asp:TextBox ID="Date_of_First_Workshop " runat="server" Visible="false"></asp:Text Box>
</td>
</tr>
</table>
-------------
return from form:
First Name: luis
Last Name: hernandez
Title: test
Organization: hgac
Address: 3555 timmons
City: houston
State: tx
Zip Code: 77027
Phone #: 7134445555
Cell Phone #: 713445555
Email: luis.hernandez@h-gac.com
Workshop_One_Date: True
Date_of_First_Workshop: April 23, 2010
Workshop_Two_Date: True
Date_of_Second_Workshop: May 11, 2010
Your Comments: : fema test 012
-------------
My question is: How can i keep the checkbox id from displaying and how can i make the textbox id display a name without the underscores?
Please help. thank you again for your time.
Sir,
Below, please find a code that seems to function but i'd like your opinion.
vbcode:
<script runat="server">
Protected Sub CheckBox1_CheckedChanged(B
Dim Workshop_One_Date As CheckBox = CType(RSVPForm1.FindContro
Dim Date_of_First_Workshop As TextBox = CType(RSVPForm1.FindContro
Date_of_First_Workshop.Vis
If Workshop_One_Date.Checked = True Then
Date_of_First_Workshop.Tex
Date_of_First_Workshop.Vis
Else
Date_of_First_Workshop.Tex
End If
End Sub
</script>
------------
code that calls the checkbox
<table cellpadding="0" cellspacing="0" style="border-color:gray" border="0">
<tr>
<td>
<asp:CheckBox ID="Workshop_One_Date" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox
</td>
<td>
<asp:TextBox ID="Date_of_First_Workshop
</td>
</tr>
</table>
-------------
return from form:
First Name: luis
Last Name: hernandez
Title: test
Organization: hgac
Address: 3555 timmons
City: houston
State: tx
Zip Code: 77027
Phone #: 7134445555
Cell Phone #: 713445555
Email: luis.hernandez@h-gac.com
Workshop_One_Date: True
Date_of_First_Workshop: April 23, 2010
Workshop_Two_Date: True
Date_of_Second_Workshop: May 11, 2010
Your Comments: : fema test 012
-------------
My question is: How can i keep the checkbox id from displaying and how can i make the textbox id display a name without the underscores?
Please help. thank you again for your time.
ASKER
rajapandian_81:
i've placed a hidden field next to a text box
<input id="Hidden1" type="hidden" runat="server" />
now i have programmed into the sub the following:
Dim Hidden1 As HiddenField = RSVPForm1.FindControl("Hid den1")
Date_of_First_Workshop.Tex t = Hidden1.Value
i'm getting this error at runtime:
Unable to cast object of type 'System.Web.UI.HtmlControl s.HtmlInpu tHidden' to type 'System.Web.UI.WebControls .HiddenFie ld'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastExceptio n: Unable to cast object of type 'System.Web.UI.HtmlControl s.HtmlInpu tHidden' to type 'System.Web.UI.WebControls .HiddenFie ld'.
any thoughts as to how to get the value of a hidden field?
i've placed a hidden field next to a text box
<input id="Hidden1" type="hidden" runat="server" />
now i have programmed into the sub the following:
Dim Hidden1 As HiddenField = RSVPForm1.FindControl("Hid
Date_of_First_Workshop.Tex
i'm getting this error at runtime:
Unable to cast object of type 'System.Web.UI.HtmlControl
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastExceptio
any thoughts as to how to get the value of a hidden field?
----------> How can i keep the checkbox id displaying
You can use ID property to get id of checkbox like below.
Dim strCheckBoxId As String
strCheckBoxId = CheckBox1.ID()
OR
Dim strCheckBoxId As String
strCheckBoxId = Workshop_One_Date.ID()
------> how can i make the textbox id display a name without the underscores?
You can use Replace command to replace the underscores to blank space like below.
strCheckBoxId = strCheckBoxId.Replace("_", " ")
You can use ID property to get id of checkbox like below.
Dim strCheckBoxId As String
strCheckBoxId = CheckBox1.ID()
OR
Dim strCheckBoxId As String
strCheckBoxId = Workshop_One_Date.ID()
------> how can i make the textbox id display a name without the underscores?
You can use Replace command to replace the underscores to blank space like below.
strCheckBoxId = strCheckBoxId.Replace("_",
ASKER
rajapandian_81:
Thank you for your suggestion.
Below, please find my sub code. It's not working and still returns checkboxID with underscores. Can you please review and let me know where i went wrong?
----------
Protected Sub CheckBox1_CheckedChanged(B yVal sender As Object, ByVal e As System.EventArgs)
Dim Workshop_One_Date As CheckBox = CType(RSVPForm1.FindContro l("Worksho p_One_Date "), CheckBox)
Dim Date_of_First_Workshop As TextBox = CType(RSVPForm1.FindContro l("Date_of _First_Wor kshop"), TextBox)
'Dim Hidden1 As HiddenField = RSVPForm1.FindControl("Hid den1")
Date_of_First_Workshop.Vis ible = "false"
Dim strWorkshop_One_Date As String
strWorkshop_One_Date = Workshop_One_Date.ID()
Dim strDate_of_First_Workshop As String
strDate_of_First_Workshop = Date_of_First_Workshop.ID( )
If Workshop_One_Date.Checked = True Then
'Workshop_One_Date.Attribu tes.Add("A pril 23, 2010", ToString())
strWorkshop_One_Date = strWorkshop_One_Date.Repla ce("_", " ")
strDate_of_First_Workshop = strDate_of_First_Workshop. Replace("_ ", " ")
Date_of_First_Workshop.Tex t = "April 23, 2010"
Date_of_First_Workshop.Vis ible = "true"
' Date_of_First_Workshop.Tex t = Hidden1.Value
Else
Workshop_One_Date.Text = " "
Date_of_First_Workshop.Tex t = ""
End If
End Sub
------------
Thank you for your suggestion.
Below, please find my sub code. It's not working and still returns checkboxID with underscores. Can you please review and let me know where i went wrong?
----------
Protected Sub CheckBox1_CheckedChanged(B
Dim Workshop_One_Date As CheckBox = CType(RSVPForm1.FindContro
Dim Date_of_First_Workshop As TextBox = CType(RSVPForm1.FindContro
'Dim Hidden1 As HiddenField = RSVPForm1.FindControl("Hid
Date_of_First_Workshop.Vis
Dim strWorkshop_One_Date As String
strWorkshop_One_Date = Workshop_One_Date.ID()
Dim strDate_of_First_Workshop As String
strDate_of_First_Workshop = Date_of_First_Workshop.ID(
If Workshop_One_Date.Checked = True Then
'Workshop_One_Date.Attribu
strWorkshop_One_Date = strWorkshop_One_Date.Repla
strDate_of_First_Workshop = strDate_of_First_Workshop.
Date_of_First_Workshop.Tex
Date_of_First_Workshop.Vis
' Date_of_First_Workshop.Tex
Else
Workshop_One_Date.Text = " "
Date_of_First_Workshop.Tex
End If
End Sub
------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
rajapandian 81,
Thank you. when i implemented your solution, it seems like placing the code breaks the "if -- End If" sub. My code is as follows:
-------
<script runat="server">
Protected Sub CheckBox1_CheckedChanged(B yVal sender As Object, ByVal e As System.EventArgs)
Dim Workshop_One_Date As CheckBox = CType(RSVPForm1.FindContro l("Worksho p_One_Date "), CheckBox)
Dim Date_of_First_Workshop As TextBox = CType(RSVPForm1.FindContro l("Date_of _First_Wor kshop"), TextBox)
'Dim Hidden1 As HiddenField = RSVPForm1.FindControl("Hid den1")
Date_of_First_Workshop.Vis ible = "false"
Dim strWorkshop_One_Date As String
strWorkshop_One_Date = Workshop_One_Date.ID()
Dim strDate_of_First_Workshop As String
strDate_of_First_Workshop = Date_of_First_Workshop.ID( )
If Workshop_One_Date.Checked = True Then
Workshop_One_Date.LabelAtt ributes.Ad d("Worksho p One Date", "April 23, 2010")
strWorkshop_One_Date = strWorkshop_One_Date.Repla ce("_", " ")
Page.ClientScript.Register StartupScr ipt(Page.G etType(), "TxtBoxSelect", "<script language=JavaScript>alert( '" + strWorkshop_One_Date + "")</script>")
strDate_of_First_Workshop = strDate_of_First_Workshop. Replace("_ ", " ")
Date_of_First_Workshop.Tex t = "April 23, 2010"
Date_of_First_Workshop.Vis ible = "true"
' Date_of_First_Workshop.Tex t = Hidden1.Value
Else
Workshop_One_Date.Text = " "
Date_of_First_Workshop.Tex t = ""
End If
End Sub
</script>
---------
Also, I have been looking at the checkbox attribute:
Dim Workshop_One_Date As New CheckBox
Workshop_One_Date.LabelAtt ributes.Ad d("Date of Workshop", "April 23, 2010")
and placing that in the FormLoad sub. i got this from the following:
http://www.15seconds.com/issue/040804.htm
maybe the checkbox has a lable attribute that can be accessed and display a different name, etc.
Thanks,
Thank you. when i implemented your solution, it seems like placing the code breaks the "if -- End If" sub. My code is as follows:
-------
<script runat="server">
Protected Sub CheckBox1_CheckedChanged(B
Dim Workshop_One_Date As CheckBox = CType(RSVPForm1.FindContro
Dim Date_of_First_Workshop As TextBox = CType(RSVPForm1.FindContro
'Dim Hidden1 As HiddenField = RSVPForm1.FindControl("Hid
Date_of_First_Workshop.Vis
Dim strWorkshop_One_Date As String
strWorkshop_One_Date = Workshop_One_Date.ID()
Dim strDate_of_First_Workshop As String
strDate_of_First_Workshop = Date_of_First_Workshop.ID(
If Workshop_One_Date.Checked = True Then
Workshop_One_Date.LabelAtt
strWorkshop_One_Date = strWorkshop_One_Date.Repla
Page.ClientScript.Register
strDate_of_First_Workshop = strDate_of_First_Workshop.
Date_of_First_Workshop.Tex
Date_of_First_Workshop.Vis
' Date_of_First_Workshop.Tex
Else
Workshop_One_Date.Text = " "
Date_of_First_Workshop.Tex
End If
End Sub
</script>
---------
Also, I have been looking at the checkbox attribute:
Dim Workshop_One_Date As New CheckBox
Workshop_One_Date.LabelAtt
and placing that in the FormLoad sub. i got this from the following:
http://www.15seconds.com/issue/040804.htm
maybe the checkbox has a lable attribute that can be accessed and display a different name, etc.
Thanks,
ASKER
Hello,
I have a user control with an asp:checkbox next to a description of a workshop. i'm being asked to program the checkbox so that when a user checks the checkbox, the checkbox control returns the name of the checkbox (in a string format with other than the name of the checkbox) and a string value (other than just "true" or "false" . For example, if checkbox ID="chk_workshop_01", i'm trying to replace the name of this checkbox control to "Workshop One Date:" and if "chk_workshop_01.checked = true" Then replace the value "true" with a string like "April 23, 2010"
I'm trying to work with the labelattributes like this:
chk_workshop_01.LabelAttri butes.Add( "April 23, 2010", "lblWorkshop_01") but I'm not having any success.
All i need is a return from the form is a checkbox control with a string name and a value other than "true" or "false" instead of "true" or "false"
Any help with this is greatly appreciated.
I have a user control with an asp:checkbox next to a description of a workshop. i'm being asked to program the checkbox so that when a user checks the checkbox, the checkbox control returns the name of the checkbox (in a string format with other than the name of the checkbox) and a string value (other than just "true" or "false" . For example, if checkbox ID="chk_workshop_01", i'm trying to replace the name of this checkbox control to "Workshop One Date:" and if "chk_workshop_01.checked = true" Then replace the value "true" with a string like "April 23, 2010"
I'm trying to work with the labelattributes like this:
chk_workshop_01.LabelAttri
All i need is a return from the form is a checkbox control with a string name and a value other than "true" or "false" instead of "true" or "false"
Any help with this is greatly appreciated.
As I have been trying to tell you in your other question, you are on the wrong track. You either need to modify the code which is reading the value of the checkbox or you need to use a property in the usercontrol which you set according to the value of the checkbox. As I have asked in your other question, how are the values received from you usercontrol?
ASKER
Thank You very much!
ASKER