Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Best practice - dynamic controls vs page life cycle vs viewstate

Reply
Thread Tools

Best practice - dynamic controls vs page life cycle vs viewstate

 
 
HP
Guest
Posts: n/a
 
      03-25-2007
Hi there

The problem of dynamically created controls vs viewstate is widely
known one. To access values of controls they have to be recreated on
Page_Load.

Unfortunately it causes many problems in the following (rather common,
I guess) scenario:

The controls are created dynamically. Their number and contents
depends on some DB values. User can add/delete data which should cause
changing the number of controls.

The problem:

Controls have to be drawn during page_load. Events have to be handled
during handlers cycle which occurs AFTER page_load. So if user changes
the state of database, the controls will be drawn based on data
fetched BEFORE the new changes are applied.


I'm trying to overcome this by checking on pageload which button was
fired (by iterating through Request.Form) but it's a rather dirty
solution.

thanks for your ideas
HP

 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      03-26-2007
I have done numerous dynamic control pages and have not had the problems you
have. I currently do not have an example, so I will have to dig something
up, but I do not remember as much pain.

I would stay away from using Page_Load to check things, as much as possible.
There may be an exception to this rule that I have missed, but Page_Load for
anything other than loading when not IsPostBack is generally a bad idea.

The ViewState fires off in between the Init routine(s) and Load, so you can
pull a lot back prior to page load. I do not think I did anything super
special with dynamic controls, but, if so, I would paint them in at
Page_Load initially and then factor them in as ViewState is grabbed.

I will have to see if I have time to resurrect some examples I have done
(older production samples from previous assignments) or find an URL for you.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*********************************************
Think outside the box!
*********************************************
"HP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi there
>
> The problem of dynamically created controls vs viewstate is widely
> known one. To access values of controls they have to be recreated on
> Page_Load.
>
> Unfortunately it causes many problems in the following (rather common,
> I guess) scenario:
>
> The controls are created dynamically. Their number and contents
> depends on some DB values. User can add/delete data which should cause
> changing the number of controls.
>
> The problem:
>
> Controls have to be drawn during page_load. Events have to be handled
> during handlers cycle which occurs AFTER page_load. So if user changes
> the state of database, the controls will be drawn based on data
> fetched BEFORE the new changes are applied.
>
>
> I'm trying to overcome this by checking on pageload which button was
> fired (by iterating through Request.Form) but it's a rather dirty
> solution.
>
> thanks for your ideas
> HP
>


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-26-2007
dynamic control should be recreated in oninit so they can receive their
postback data and fire events.

if the page need to change controls, then in the page load, or click
event delete the old controls (simple if in a place holder) and create
new ones before prerender.

-- bruce (sqlwork.com)

HP wrote:
> Hi there
>
> The problem of dynamically created controls vs viewstate is widely
> known one. To access values of controls they have to be recreated on
> Page_Load.
>
> Unfortunately it causes many problems in the following (rather common,
> I guess) scenario:
>
> The controls are created dynamically. Their number and contents
> depends on some DB values. User can add/delete data which should cause
> changing the number of controls.
>
> The problem:
>
> Controls have to be drawn during page_load. Events have to be handled
> during handlers cycle which occurs AFTER page_load. So if user changes
> the state of database, the controls will be drawn based on data
> fetched BEFORE the new changes are applied.
>
>
> I'm trying to overcome this by checking on pageload which button was
> fired (by iterating through Request.Form) but it's a rather dirty
> solution.
>
> thanks for your ideas
> HP
>

 
Reply With Quote
 
HP
Guest
Posts: n/a
 
      04-01-2007
On Mar 26, 4:23 am, "Cowboy \(Gregory A. Beamer\)"
<(E-Mail Removed)> wrote:
> I have done numerous dynamic control pages and have not had the problems you
> have. I currently do not have an example, so I will have to dig something
> up, but I do not remember as much pain.




> I would stay away from using Page_Load to check things, as much as possible.
> There may be an exception to this rule that I have missed, but Page_Load for
> anything other than loading when not IsPostBack is generally a bad idea.


could you explain why is that? because it's possible that something
was changed before the Page_Load in the code?

thanks
HP

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
3+ basic questions for asp:RadioButton, related to ViewState, life cycle, javascript Ryan Liu ASP .Net 3 03-27-2009 05:33 AM
Page life cycle and Page.IsValid property Gary Larimer ASP .Net 2 08-01-2008 10:57 PM
What does "Page Load" and "Page Unload", "Page Life Cycle" exactlymean???? lander ASP .Net 5 03-03-2008 02:06 PM
asp.net 1.1 page and controls life-cycle Fred ASP .Net 5 01-23-2006 02:19 PM
reusable datagrid, using viewstate items as for SQL statements / problems with life cycle TB ASP .Net 12 10-27-2005 04:38 PM



Advertisments