Please explain strange viewstate behavior...

G

Guest

I am dynamically adding an HtmlInputHidden element with different values.
The problem is the first time I add it with a given value and submit it then
change the value within the Page_Load event it still has the original value.
I am guessing this has something to do with viewstate. I have turned off
viewstate at the page level, but the issue still occurs. Any suggestions?

The code is basic:
HtmlInputHidden phihAction = new HtmlInputHidden();

phihAction.ID = "hdnAction";
phihAction.Value = ((short)pactAction).ToString();
mfrmUser.Controls.Add( phihAction );

pactAction is an enumeration that changes based on action (i.e. 1=Add, 2=Edit)

Any help in understanding why it does what it does and how to work around it
would be greatly appreciated.
 
E

Eliyahu Goldin

Robert,

You need to check IsPostBack property befory assigning the value:

HtmlInputHidden phihAction = new HtmlInputHidden();

phihAction.ID = "hdnAction";
if (IsPostBack)
phihAction.Value = ((short)pactAction).ToString();
mfrmUser.Controls.Add( phihAction );

Eliyahu
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top