Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Muaz Bashara   on Nov 12 In Asp.net Category.

  
Question Answered By: Erma Henry   on Nov 12

Can I make a suggestion to everyone.

In each of Page_Load, Control_Load,  page  REnder, Control Render you write a "Response.Write" so that you can see th eevnets as they are firing.

What you will see is this - say you have a control in a page, in that control you have a button, which you click

pageload
controlload
buttonclick
pageprerender
controlprerender

do when you click the button  the event is fired after both the page and the control is loaded, so if you databind in there it doesn't show up until you postback again.
( its a pain in the ar*e I know)

So do your binding in pre_render.

I have done it all in page_load but it involved ViewState(which is like a session  but page specific, and rebinding.

Using pre-render is not cool. This is why :
Say you have a control which alters the html of its parent, then you may need to make changes in in pre_render.
But - if you have another control in that same page, with a button that makes a postback then IT needs to be bound in page_load of the parent (else we are a step behind).
So one defeats the other.

I recently had to do something where I was adding controls  programatically, I eventually had to split up what I was doing.

I had to add  a dummy control ( in pageload )


Controls.AddAt(0, blank)
Controls.AddAt(1, mycontrol)

Then in page render I had to
Controls.Remove(0)
Controls.AddAt(0, somecontrol)
Controls.AddAt(2,somecontrol2)
Controls.AddAt(3,somecontrol3)

where mycontrol was another control that had a button to postback.


You can see that at http://www.cardiffwebdesign.com

The whole thing is a page with 2 controls in it, the actual page being the base of it all, the menus, the images, etc. the content is added via a control.
The dropdown is one control and alters the parent pages html i.e. the menus. So this had to be done in page prerender ( since the dropdown control postsback after the page has already loaded)
The Bits with all the writing on it is the other control I mentioned, to make a postback work  it had to be done in pageload.

And I had to keep the order of adding the controls - but later additions had to be done in pre_render whilst earlier ones in page_load. Hence the removeAt came in very handy - essential in fact.

Note the menu at the above url, improved GotDotNEtMenu's - call  'em GotDotNEtMultMenus - altered so you can have as many as you want in a single page. Cool eh ?
Think I'll release them when I've finished them.

I know, i know, I know  ... kinda resembles GotDotNet in general eh ? ( I'm a programmer not a designer ! - I'm just waiting for the law suit ! )

Soz guys - ain't giving the code or html away - it took ages. But will help if I can. Its just a case of mess about with it trying your hardest NOT to use pre_render unless you really have to.

Share: 

 
 
Didn't find what you were looking for? Find more on problem with session interacting between 2 webforms.. Or get search suggestion and latest updates.


Tagged: