HiddenField

  • Thread starter Thread starter hharry
  • Start date Start date
H

hharry

Hello All,

I am trying to make use the HiddenField server control to make a
server-side variable visible to a client script.
I set the value of the HiddenField inside of the Page_Load event.

protected void Page_Load(object sender, EventArgs e)
{
this.myHiddenField.Value = myVar;
}

I am able to access this value in my client script.
If a PostBack occurs, myHiddenField.Value is updated server-side, but
the value client-side always remains the same - the initial value when
the page first loads...

I'm missing something...pointers appreciated..

Thanks in advance
 
What do you mean when you say the value is updated server side? Have you
stepped through with the debugger to be sure? Have you viewed the output
source to make sure the hidden field value is not updated on the client
side?

I tried a simple example based on your scenario, and the values are updated
as expected.
 
Ensure that you only assign the initial value when the page loads for the
first time:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
this.myHiddenField.Value = myVar;
}
 
What do you mean when you say the value is updated server side? Have you
stepped through with the debugger to be sure? Have you viewed the output
source to make sure the hidden field value is not updated on the client
side?

I tried a simple example based on your scenario, and the values are updated
as expected.











- Show quoted text -

HI... did you actually initalize your code in side a
if(!ispostback)
{
///here
}

and update it in
if(ispostback)
{
///here
}

can you put your code sample ... just to have a quick look...

Thanks
Md. Masudur Rahman (Munna)
Kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
What do you mean when you say the value is updated server side? Have you
stepped through with the debugger to be sure? Have you viewed the output
source to make sure the hidden field value is not updated on the client
side?


I step-thru the code and the value is updated, but when my client-
script runs, the value is not updated and if I right-click and select
view source, the value has not been updated.
Puzzled..
 
Back
Top