HiddenField

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
 
B

Brandon Gano

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.
 
G

Guest

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;
}
 
M

Masudur

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
 
H

hharry

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..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top