Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > CreateChildControls Event before Click Event

Reply
Thread Tools

CreateChildControls Event before Click Event

 
 
Mark Sisson
Guest
Posts: n/a
 
      07-17-2003
Issue:
I want to create a control that will accept a click event and then in
response completely change it's look and feel. This could potentially
mean a new completely new set of child controls than what the control
had previously.

Problem:
The problem is that the click event holds the key in determining what
the new layout will be but don't you have this info when you're in the
CreateChildControls? This happens before the click event!

Example:
I'm working on a navigation control with "<< prev 1 2 3 next >>" look
and feel. This example would have 7 LinkButtons. When the user
presses the #2 link I want the control to get the event, shift it's
numbering to "2 3 4", and potentially change the #2 LinkButton to a
Label or perhaps radically change the look and feel.

Questions:
1. If I want the control to receive the click event do I have to
create my controls in the CreateChildControls event? I've tried moving
the entire control creation to the PreRender but then the wiring of
EventHandlers doesn't work and my link clicks don't work.

2. Should I build the entire raw HTML in the PreRender? Then would I
hookup my own client-side script to post back? Doesn't this defeat all
the magic of ASP.NET?

3. Is there a way to "peak" at the object that caused the event to
fire in the CreateChildControl event? In my example above, all I just
need to know what LinkButton was pressed before I build things in
CreateChildControls. My guess is no. you've probably got to
completely reset the entire f***ing DOM in the Init just so ASP.NET
can match the event with it's firing control. Then you complete scrap
it and rebuild a new control. What a waste of CPU time!!!!

FRUSTRATING!!! WHY IS THIS SO DAMN DIFFICULT!!!!!!!

TIA for you help.
 
Reply With Quote
 
 
 
 
Victor Garcia Aprea [MVP]
Guest
Posts: n/a
 
      07-17-2003
Hi Mark,

You always create your child controls in CreateChildControls. What you have
to do is to recreate your childs after the click event (ie.PreRender) so
your CreateChildControls method gets a chance to run with the updated value
and creates its childs accordingly. Note that you're not really wasting
anything. CreateChildControls needs to run before the event firing logic in
order to be able to reconstruct the previously control tree in order to been
able to respond to events.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx

To contact me remove 'NOSPAM'. Please post all questions to the newsgroup

and not by private mail.
"Mark Sisson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Issue:
> I want to create a control that will accept a click event and then in
> response completely change it's look and feel. This could potentially
> mean a new completely new set of child controls than what the control
> had previously.
>
> Problem:
> The problem is that the click event holds the key in determining what
> the new layout will be but don't you have this info when you're in the
> CreateChildControls? This happens before the click event!
>
> Example:
> I'm working on a navigation control with "<< prev 1 2 3 next >>" look
> and feel. This example would have 7 LinkButtons. When the user
> presses the #2 link I want the control to get the event, shift it's
> numbering to "2 3 4", and potentially change the #2 LinkButton to a
> Label or perhaps radically change the look and feel.
>
> Questions:
> 1. If I want the control to receive the click event do I have to
> create my controls in the CreateChildControls event? I've tried moving
> the entire control creation to the PreRender but then the wiring of
> EventHandlers doesn't work and my link clicks don't work.
>
> 2. Should I build the entire raw HTML in the PreRender? Then would I
> hookup my own client-side script to post back? Doesn't this defeat all
> the magic of ASP.NET?
>
> 3. Is there a way to "peak" at the object that caused the event to
> fire in the CreateChildControl event? In my example above, all I just
> need to know what LinkButton was pressed before I build things in
> CreateChildControls. My guess is no. you've probably got to
> completely reset the entire f***ing DOM in the Init just so ASP.NET
> can match the event with it's firing control. Then you complete scrap
> it and rebuild a new control. What a waste of CPU time!!!!
>
> FRUSTRATING!!! WHY IS THIS SO DAMN DIFFICULT!!!!!!!
>
> TIA for you help.



 
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
createchildcontrols fires before click event hsnkamal@yahoo.com ASP .Net Web Controls 1 07-04-2007 10:56 AM
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net Building Controls 1 05-28-2004 06:23 AM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
CreateChildControls Event before Click Event Mark Sisson ASP .Net Building Controls 1 07-17-2003 03:46 AM



Advertisments