473,326 Members | 2,438 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.

Viewstate/Postback for dynamic controls. CRAZY?

I thought I had a good grip on viewstate handling, but am suprised by a
small test:

In my aspx file I have a PlaceHolder control and a button for posting
back.

Dynamically in Page_Load I create a TextBox, and add it as a control of
PlaceHolder.

I do this regardless of whether IsPostBack is true or not, to insure
the control always exists on the page.

My expectation would be that any user entered information in the
TextBox would not be available across postbacks because I am not
creating it until Page_Load, which supposedly occurs *after* controls
have loaded their viewstate and processed any postback data.

But, surprise! The information I enter into the text box is being
acquired by it somehow, as I see it show up in the test box after
clicking the button, which causes a postback.

How can my textbox be getting the user supplied data if it's created
*after* the postback data has already been processed??

... To expand the test a bit, I also modified a property of the text box
in Page_Load, but only when IsPostBack == false. In other words, I
"initialize" the TextBox's Columns property to 40. Again, my
expectation is that during postback the textbox wouldn't retain this
setting as I recreate the control after viewstate handling has occured.
But yet it retains the setting.

WHAT GIVES???????

Thanks for any insights!

Apr 10 '06 #1
2 1627
if you add any control at run time, the framework makessure that it gets
loaded completely during Page_Load and its view state has been loaded too.
Page_Load makes sure that the control tree has been fully created the you
want it to be and then it moves to nest step. And thats what you are seeing.
when you called LoadControl or AddControl in Page_Load, the framework gave
this control chance to play catch up and its view state got loaded into the
control.
"mivhaelveloz" <mi**********@hotmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
I thought I had a good grip on viewstate handling, but am suprised by a
small test:

In my aspx file I have a PlaceHolder control and a button for posting
back.

Dynamically in Page_Load I create a TextBox, and add it as a control of
PlaceHolder.

I do this regardless of whether IsPostBack is true or not, to insure
the control always exists on the page.

My expectation would be that any user entered information in the
TextBox would not be available across postbacks because I am not
creating it until Page_Load, which supposedly occurs *after* controls
have loaded their viewstate and processed any postback data.

But, surprise! The information I enter into the text box is being
acquired by it somehow, as I see it show up in the test box after
clicking the button, which causes a postback.

How can my textbox be getting the user supplied data if it's created
*after* the postback data has already been processed??

.. To expand the test a bit, I also modified a property of the text box
in Page_Load, but only when IsPostBack == false. In other words, I
"initialize" the TextBox's Columns property to 40. Again, my
expectation is that during postback the textbox wouldn't retain this
setting as I recreate the control after viewstate handling has occured.
But yet it retains the setting.

WHAT GIVES???????

Thanks for any insights!

Apr 10 '06 #2
Thanks, that's definitely what I'm seeing.. guess I was just surprised
because I've seen other articles on the web about how if you want
dynamic controls to partake in viewstate that they must be created in
Page_Init because Page_Load is too late. Maybe this was changed
sometime later and the articles I read were outdated...???

Thanks for the reply
Michael

Apr 10 '06 #3

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

Similar topics

4
by: Tom Wisnowski | last post by:
Hello all, Here is a simple example of what I'm doing... Create a ASPX page Add a PlaceHolder(plch) and a Button(btn) to the page. In the code behind on Page_load add the following......
4
by: Chuck Ritzke | last post by:
Hi, I've searched the newsgroup and other sources to understand how to handle runtime controls and see I'm not the only one who's confused, but I'm still not quite sure of the best way to handle...
6
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
0
by: Sue | last post by:
I'm missing something very simple here, and I need an answer fairly quick if possible. I'm behind on this project now because of this... Code examples below question... I have a datagrid (DG)...
6
by: hlubocky | last post by:
I thought I had a good grasp of the problem related to dynamically creating controls, but it appears that as my application grew in complexity, the problem has resurfaced. As I understand it, in...
6
by: Peter Zolja | last post by:
Hi, I'm building a webcontrol that contains a dynamic list of other controls. My problem is that when I add or remove an item the synchronization between the ViewState and the Controls...
2
by: Dica | last post by:
i've got a simple page with a dropdown list of employees and a series of checkboxs showing their skills. the checkboxs are created dynamically from a sql statement and viewstate = false is set on...
0
by: Scott Roberts | last post by:
I always thought that the viewstate "keys" included the control ID. As long as the control IDs were unique, there shouldn't be any conflicts. Well, it appears that that may not be the case with...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.