Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > HtmlInputHidden value set on client not getting to server postback

Reply
Thread Tools

HtmlInputHidden value set on client not getting to server postback

 
 
Scott
Guest
Posts: n/a
 
      11-23-2004
I'm having a problem with maintaining a form dirty flag that is shared
between the client and server. I'm trying to use an HtmlInputHidden control
(that is set to "true" on the client when changes are made) to control the
processing on the server when the form is posted back. The trouble is, on the
client side after the initial load the value of the hidden element is
undefined, but it was set to false on the server in Page_Unload, and after
post-back, the value of the hidden element is not updated in ViewState. In
other words, its as though the client side element in HTML and the server
side element declared are not the same elements.

Here is how the element is set up:

In .aspx page:
<input id="hdnDirtyFlag" type=hidden runat="server">
This IS inside the <form></form> element.

In .aspx.cs class:
protected System.Web.UI.HtmlControls.HtmlInputHidden hdnDirtyFlag;

In .aspx.cs Page_Load, if (! IsPostBack) only:
hdnDirtyFlag.Value = "false";

In .aspx.cs LoadViewState:
sDirtyFlag = (string) ViewState["hdnDirtyFlag"];

In client-side script:
function FormDirty() {
alert(document.getElementById('hdnDirtyFlag').Valu e); // test -
displays undefined
document.getElementById('hdnDirtyFlag').Value = 'true';
alert(document.getElementById('hdnDirtyFlag').Valu e); // test -
displays "true"
}
This IS being triggered correctly from input elements using ...
onchange="FormDirty();" ...


I've tracked the value of the hidden element in the page lifecycle:

First time through:
OnInit (before base.OnInit): ""
OnInit (after base.OnInit): ""
Page_Load (! IsPostBack): "false" (as assigned)
Page_PreRender: "false"

On client in FormDirty() function before a change event: undefined
On client in FormDirty() function after a change event: "true"

At postback:
OnInit (before base.OnInit): ""
OnInit (after base.OnInit): ""
LoadViewState (before base.LoadViewState): null
LoadViewState (after base.LoadViewState): null
Page_Load (IsPostBack): "false"
Page_PreRender: "false"

Any help in understanding what's going wrong would be appreciated. My goal
is to be able to determine if the hidden element's value was set to "true" on
the client when processing the post-back on the server.

 
Reply With Quote
 
 
 
 
Scott
Guest
Posts: n/a
 
      11-26-2004
For future reference, changing the reference to the hidden field in the
client-side script to "FormName.hdnDirtyFlag.value" instead of
"document.getElementById('hdnDirtyFlag').value " fixes the problem described
here.

....

"Scott" wrote:

> I'm having a problem with maintaining a form dirty flag that is shared
> between the client and server. I'm trying to use an HtmlInputHidden control
> (that is set to "true" on the client when changes are made) to control the
> processing on the server when the form is posted back. The trouble is, on the
> client side after the initial load the value of the hidden element is
> undefined, but it was set to false on the server in Page_Unload, and after
> post-back, the value of the hidden element is not updated in ViewState. In
> other words, its as though the client side element in HTML and the server
> side element declared are not the same elements.
>
> Here is how the element is set up:
>
> In .aspx page:
> <input id="hdnDirtyFlag" type=hidden runat="server">
> This IS inside the <form></form> element.
>
> In .aspx.cs class:
> protected System.Web.UI.HtmlControls.HtmlInputHidden hdnDirtyFlag;
>
> In .aspx.cs Page_Load, if (! IsPostBack) only:
> hdnDirtyFlag.Value = "false";
>
> In .aspx.cs LoadViewState:
> sDirtyFlag = (string) ViewState["hdnDirtyFlag"];
>
> In client-side script:
> function FormDirty() {
> alert(document.getElementById('hdnDirtyFlag').Valu e); // test -
> displays undefined
> document.getElementById('hdnDirtyFlag').Value = 'true';
> alert(document.getElementById('hdnDirtyFlag').Valu e); // test -
> displays "true"
> }
> This IS being triggered correctly from input elements using ...
> onchange="FormDirty();" ...
>
>
> I've tracked the value of the hidden element in the page lifecycle:
>
> First time through:
> OnInit (before base.OnInit): ""
> OnInit (after base.OnInit): ""
> Page_Load (! IsPostBack): "false" (as assigned)
> Page_PreRender: "false"
>
> On client in FormDirty() function before a change event: undefined
> On client in FormDirty() function after a change event: "true"
>
> At postback:
> OnInit (before base.OnInit): ""
> OnInit (after base.OnInit): ""
> LoadViewState (before base.LoadViewState): null
> LoadViewState (after base.LoadViewState): null
> Page_Load (IsPostBack): "false"
> Page_PreRender: "false"
>
> Any help in understanding what's going wrong would be appreciated. My goal
> is to be able to determine if the hidden element's value was set to "true" on
> the client when processing the post-back on the server.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET: HtmlInputHidden = Nothing Mały Piotruœ ASP .Net 0 12-04-2005 03:37 PM
How to get HtmlInputHidden value in a popup window? Jack ASP .Net 4 11-30-2005 02:35 AM
No Update for HtmlInputHidden -- Bug or Feature? heybrakywacky@hotmail.com ASP .Net 6 10-24-2005 10:48 PM
HtmlInputHidden Control Julius Fenata ASP .Net 0 01-18-2005 10:26 AM
adding a HtmlInputHidden to a HtmlForm not working Jiho Han ASP .Net 2 02-11-2004 03:22 PM



Advertisments