barnesco
asked on
Passing a javascript value to a code behind page
How would you pass a javascript value back to a code behind page in asp.net, such as:
FROM: (onclick function...)
rbRecurEventValue.value = 1
TO CODE BEHIND:
Public rbRecurEventValue as Integer
If rbRecurEventValue = 1 Then
[do something]
End if
I'm receiving a value of 0 when passing it to the code behind page.
Thanks.
FROM: (onclick function...)
rbRecurEventValue.value = 1
TO CODE BEHIND:
Public rbRecurEventValue as Integer
If rbRecurEventValue = 1 Then
[do something]
End if
I'm receiving a value of 0 when passing it to the code behind page.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I see what you're doing now--passing it to a hidden field, then passing it to the code behind variable, but I might be missing something. I have:
in javascript:
document.getElementById("l blRecurEve nt").value =1;
in aspx:
<asp:Label ID="lblRecurEvent" runat="server" style="display:none;"></as p:Label>
in code behind:
RecurEvent = lblRecurEvent.Text
If RecurEvent = 1 Then
[do something]
End if
Where is going wrong? Thanks.
in javascript:
document.getElementById("l
in aspx:
<asp:Label ID="lblRecurEvent" runat="server" style="display:none;"></as
in code behind:
RecurEvent = lblRecurEvent.Text
If RecurEvent = 1 Then
[do something]
End if
Where is going wrong? Thanks.
ASKER
It seems the value is not being set with document.getElementById("l blRecurEve nt").value =1.
I've tried document.getElementById("l blRecurEve nt").text= 1, but that doesn't work, either.
I've tried document.getElementById("l
ASKER
The question now is how do you assign a javascript value to an aspx control?
ASKER
Finally figured it out on two fronts:
First have to declare the variable, then assign the value as in:
var elemRecurValue = document.getElementById("v arname")
elemRecurValue.value=1
Second, and this is the one that took all %$^&* day to figure out: You can't assign a value to a label using javascript!!! For some dumb reason, it just won't work. It will for a textbox, so I used a textbox hidden field, and yes, it works.
First have to declare the variable, then assign the value as in:
var elemRecurValue = document.getElementById("v
elemRecurValue.value=1
Second, and this is the one that took all %$^&* day to figure out: You can't assign a value to a label using javascript!!! For some dumb reason, it just won't work. It will for a textbox, so I used a textbox hidden field, and yes, it works.
Sorry about the Label you are right it must be TextBox.
ASKER