473,378 Members | 1,467 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,378 software developers and data experts.

ViewState and re-creating ASP.Net page controls

I have an ASP.Net page on which there are serveral static controls
(listboxes, radiobuttonlist and textboxes). These controls are used to
create criteria from which the code-behind will dynamically create 1-n
datagrids.

When the Submit button is clicked I need to save (in viewstate) the
contents of the criteria controls so that I can recreate the dynamic
DataGrid(s) in the LoadViewState (overloaded method). I need to do
this so that the DataGrid controls are available for the page's
control heirarchy when the Changed events are serviced (i.e.
Datagrid:SelectedIndexchanged event).

All that being said... I know that I can save the criteria control
values to the ViewState via "brute force" (saving the values of each
control into an array, etc) and then reference the values when the
DataGrids are to be re-created in the LoadViewState. My question is -
is there a more elegant/efficient way of accessing the control values
prior to the Load_Page event?

I know that the listboxes, radiobuttonlist and textboxes are all
properly maintaining state (in their respective postback data
collections - via IPostbackDataHandler) but I don't know how to access
the data from the page prior to Page Load.

I look forward to your input on this, yet-another-headbanger, problem.

Glenn
Nov 18 '05 #1
6 5985
The following .Net SDK article should help:

http://msdn.microsoft.com/library/de...nLifecycle.asp

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Glenn Owens" <go****@nixonpeabody.com> wrote in message
news:bc**************************@posting.google.c om...
I have an ASP.Net page on which there are serveral static controls
(listboxes, radiobuttonlist and textboxes). These controls are used to
create criteria from which the code-behind will dynamically create 1-n
datagrids.

When the Submit button is clicked I need to save (in viewstate) the
contents of the criteria controls so that I can recreate the dynamic
DataGrid(s) in the LoadViewState (overloaded method). I need to do
this so that the DataGrid controls are available for the page's
control heirarchy when the Changed events are serviced (i.e.
Datagrid:SelectedIndexchanged event).

All that being said... I know that I can save the criteria control
values to the ViewState via "brute force" (saving the values of each
control into an array, etc) and then reference the values when the
DataGrids are to be re-created in the LoadViewState. My question is -
is there a more elegant/efficient way of accessing the control values
prior to the Load_Page event?

I know that the listboxes, radiobuttonlist and textboxes are all
properly maintaining state (in their respective postback data
collections - via IPostbackDataHandler) but I don't know how to access
the data from the page prior to Page Load.

I look forward to your input on this, yet-another-headbanger, problem.

Glenn

Nov 18 '05 #2

Kevin, while I appreciate your providing a link to this familiar MSDN
article I am fairly aware of the basics of the page lifecycle.

Perhaps you could provide some insight as to the problem (namely the
re-creation of Dynamic controls based on static non-viewstate - i.e.
post data collection control values). I haven't found any articles on
that particular topic.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
It's a sequence issue. It's not a simple answer, and I didn't understand all
of what you posted, so I posted a reference. However, I will address each
point of your post:
I have an ASP.Net page on which there are serveral static controls
(listboxes, radiobuttonlist and textboxes). These controls are used to
create criteria from which the code-behind will dynamically create 1-n
datagrids.
Define "static controls." A Web Control is not static, and static HTML is
not a Control. The rest of the answer depends upon your answer to this
question, as Controls maintain their own State.
When the Submit button is clicked I need to save (in viewstate) the
contents of the criteria controls so that I can recreate the dynamic
DataGrid(s) in the LoadViewState (overloaded method). I need to do
this so that the DataGrid controls are available for the page's
control heirarchy when the Changed events are serviced (i.e.
Datagrid:SelectedIndexchanged event).
Still confused. Again, the "criteria controls" should maintain their own
State.
All that being said... I know that I can save the criteria control
values to the ViewState via "brute force" (saving the values of each
control into an array, etc) and then reference the values when the
DataGrids are to be re-created in the LoadViewState. My question is -
is there a more elegant/efficient way of accessing the control values
prior to the Load_Page event?
Same problem.
I know that the listboxes, radiobuttonlist and textboxes are all
properly maintaining state (in their respective postback data
collections - via IPostbackDataHandler) but I don't know how to access
the data from the page prior to Page Load.
I don't understand why Page_Load is so important here. Again, it's a
sequencing issue. Page_Load occurs at a certain point in the Cycle. But it
is certainly not necessary to use it at all. What is necessary is to have
code execute in the right sequence. Page_Load occurs after all Controls have
been created, but prior to event-handling.

Finally, again, it sounds like you're using static HTML elements for some of
your Page. If you want them to maintain state, that's what Server Controls
are for. If you are using static HTML form elements, and feel that you must,
their values are constantly avaiable on the server via the Request.Form
Collection. You could certainly grab their values from the Request.Form
Collection, and put them back in the HTML when rendering your static HTML,
but again, that's what Server Controls are for.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Glenn Owens" <go****@nixonpeabody.com> wrote in message
news:ed*************@tk2msftngp13.phx.gbl...
Kevin, while I appreciate your providing a link to this familiar MSDN
article I am fairly aware of the basics of the page lifecycle.

Perhaps you could provide some insight as to the problem (namely the
re-creation of Dynamic controls based on static non-viewstate - i.e.
post data collection control values). I haven't found any articles on
that particular topic.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4

OK, please forgive my frustration level as I've been working on this
problem for some days.

I believe that I've found the last remaining problem. Apparently, for
some unknow reason, if I add a control (i.e. DataGrid) dynamically to
the .aspx page followed by a DataBind everything seems to work. If, on
the other hand, I perform the same DataBind anywhere "inside" the
ASP.Net container (i.e. TableRow, Panel, etc) the DataGrid is rendered
but the SelectedIndexChanged never fires.

So, please illuminate me as to this little idiosyncracy with ASP.Net.
This puts a real crimp in the flexibility of the page I'm designing.

I have n-DataGrids being dynamically generated based on Usre input from
a variety of APS.NET controls on the page. Thus far I have insured that
the DataGrid(s) are successfully re-created in the LoadListView (so the
the events are "wired-up" by the time of the Load_Page). Currently, in
the page, the datagrids are arranged in n-up fashion within a panel
(overflow:Auto)/table/tablerow(s)/tablecell(s). This nice visual
arragement will need to be changed if I can't find some work-around in
fairly short order.

Kevin, you've been more than patient - and I really do appreciate the
information that you've provided. Please, help with this last issue.

Thanks,
Glenn
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5
Hi Glenn,

If it's any consolation, sequence is one of the most difficult aspects of
ASP.Net to master, so when this is over, you should be a much stronger
developer!

The expression "followed by a DataBind" is not precise enough to tell me
what's going on. the DataBind method is common to ALL Server Controls, and
it binds the data in a Server Control as well as all Server Controls
contained within that Server Control. So, if you call Page.DataBind() you
are DataBinding all Controls in the Page. But if you call DataGrid.DaaBind()
it binds only that DataGrid, and all child Controls of that DataGrid.

I can tell you this much: This is definitely a sequencing issue.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Glenn Owens" <go****@nixonpeabody.com> wrote in message
news:uT*************@tk2msftngp13.phx.gbl...

OK, please forgive my frustration level as I've been working on this
problem for some days.

I believe that I've found the last remaining problem. Apparently, for
some unknow reason, if I add a control (i.e. DataGrid) dynamically to
the .aspx page followed by a DataBind everything seems to work. If, on
the other hand, I perform the same DataBind anywhere "inside" the
ASP.Net container (i.e. TableRow, Panel, etc) the DataGrid is rendered
but the SelectedIndexChanged never fires.

So, please illuminate me as to this little idiosyncracy with ASP.Net.
This puts a real crimp in the flexibility of the page I'm designing.

I have n-DataGrids being dynamically generated based on Usre input from
a variety of APS.NET controls on the page. Thus far I have insured that
the DataGrid(s) are successfully re-created in the LoadListView (so the
the events are "wired-up" by the time of the Load_Page). Currently, in
the page, the datagrids are arranged in n-up fashion within a panel
(overflow:Auto)/table/tablerow(s)/tablecell(s). This nice visual
arragement will need to be changed if I can't find some work-around in
fairly short order.

Kevin, you've been more than patient - and I really do appreciate the
information that you've provided. Please, help with this last issue.

Thanks,
Glenn
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #6

OK, here's the lastest status. I've delayed the DataBind on all
DataGrids until the panel, table, rows, cells have been
created/populated. Once these "container" controls are in place I then
cycle through the control list and locate the DataGrids and perform the
appropriate DataBind. That part works find (the DataGrids are displayed
and the User can click on a row).

Unfortunately, when the a row is clicked I now get the following error:

=============================
=============================
Server Error in '/Disbursement/Dashboard' Application.
------------------------------------------------------------------------
--------

An error has occurred because a control with auto-generated id
'AggregateDataGridInvalid' could not be located to raise a postback
event. To avoid this error, explicitly set the ID property of controls
that raise postback events.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: An error has occurred
because a control with auto-generated id 'AggregateDataGridInvalid'
could not be located to raise a postback event. To avoid this error,
explicitly set the ID property of controls that raise postback events.

Source Error:

An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:
[HttpException (0x80004005): An error has occurred because a control
with auto-generated id 'AggregateDataGridInvalid' could not be located
to raise a postback event. To avoid this error, explicitly set the ID
property of controls that raise postback events.]
System.Web.UI.Page.ProcessPostData(NameValueCollec tion postData,
Boolean fBeforeLoad) +854
System.Web.UI.Page.ProcessRequestMain() +621

=============================
=============================

I have maually "Id'd" each dynamic control in the control list so, I
suspect that there's something else going on here. I'm going to add some
exception catching logic to investigate further. You know.... this
shouldn't be this difficult!!!

Glenn
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #7

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

Similar topics

1
by: Stephen | last post by:
I have an arraylist which takes in values and im trying to add values to the array list everytime the button is clicked. Im trying to use the viewstate but seem to be getting the following build...
3
by: Pradeep | last post by:
Hi, I am storing the DataTable in a ViewState. ViewState("mydata") = dsRedemption.T_Redemption_Dtl Then I am casting the ViewState into a DataTable variable. Dim x As New DataTable x =...
1
by: Fatboycanteen | last post by:
無法載入 Viewstate。Viewstate 所要載入的控制項樹狀結構必須符合在先前要求期間用來儲存 Viewstate...
1
by: Ramez T. Mina | last post by:
Many thanks, but still need something else. I made an sql command and the resultant records is stored in array, but when I click the button to go to the next result it doesn't work. find the code...
2
by: Bill Yeager | last post by:
I have a grid that I databind with a strongly typed dataset which contains thousands of records retrieved from a database. After the dataset is retrieved from the database, I place it in...
3
by: MattC | last post by:
With respect to Peter Bromberg's article ( http://www.eggheadcafe.com/articles/20040613.asp ) I wish to store my viewstate info in the Session object rather than the cache (as it is per user...
2
by: Ryan Ternier | last post by:
I'm playing around with Cache and Viewstate. I've made a small little example that reminds me of grade 12: if(!IsPostBack) { ArrayList alTest = new ArrayList(); alTest.Add("This is from...
2
by: mohaaron | last post by:
Can anyone tell me why when trying to use the following code to deserialize the viewstate it takes a long time with a large viewstate. This really surprised as the viewstate is big, but not that...
6
by: Rob | last post by:
Hi all, I have my own object stored in the viewstate on one of my pages, as the user progresses through the next couple of pages I want to update it. In order to get my object in there I had...
4
by: DavidF | last post by:
Hi, I'm having a problem with viewstate encryption on one of my websites. To encrypt the viewstate, I'm using the following lines in my web.Config file: <pages theme="Default"...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.