Reputation: 11
I have been looking at answers here and other places but so far have not found exactly how to do this.
I have the following definition for a hidden field in my .aspx page:
<asp:HiddenField ID="hfAddressChange" runat="server" />
I set the value in a javascript function on the client:
function confirmAddressChange()
{
if (typeof document.forms[0].hfAddressChange.valueOf ==="undefined")
{
var res = (confirm('"Update Contact Addresses to Rich?"')==true);
document.forms[0].hfAddressChange.valueOf = res;
}
}
Basically I only want to set the value once.
Now I want to check the value in the code behind:
If hfAddressChange.Value <> String.Empty Then
Dim x As String = "Do Something here"
End If
However, even though I have verified that the value IS being set in the js function, it is always an empty string when it gets to my code behind.
Anyone see what the heck I'm doing wrong?
Upvotes: 1
Views: 1580
Reputation: 224913
document.forms[0].hfAddressChange.valueOf = res;
The property is value
, not valueOf
. (And it won't be undefined
earlier, either; just check !document.forms[0].hfAddressChange.value
.)
Upvotes: 1