473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Please explain strange viewstate behavior...

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.

--
Robert
Nov 19 '05 #1
1 1077
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

"rgrandidier" <rg*********@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
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.

--
Robert

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
by: DeltaOne | last post by:
#include<stdio.h> typedef struct test{ int i; int j; }test; main(){ test var; var.i=10; var.j=20;
0
by: Apogee | last post by:
I have encountered a very strange behavior of the vsnet: ASP.net: I set the ViewState of the Document to false, just to see that Literal controls need the ViewState, so I turned it on again....
10
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and...
0
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
4
by: BluDog | last post by:
Hi I am trying to test dynamically created controls, to do this i have added a placeholder to a WbForm and added the following code behind: Private Property Count() As Integer Get If...
7
by: John | last post by:
Hi all, I need finality on this once and for all please. I have a main page which contains a couple of placeholders and within these placeholders, depending on what the user presses, I load...
3
by: ntexchange05 | last post by:
I am trying to learn asp.net and build a site and i am using web matrix and vb.net. I have installed the MSDE on my windows xp pro, i am using the book calledbeginning dynamic websites with...
6
by: Frank | last post by:
Can someone please tell me when the ViewState is loaded? My understanding, based on http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconControlExecutionLifecycle.asp...
8
by: John Austin | last post by:
I need to understand why if I add a control and use AddHandler to connect its click event, it will work in Page_Load, but not in a Button_Click. The idea is that the user types some data, presses...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.