CreateChildControls Event before Click Event

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default CreateChildControls Event before Click Event

    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.
    Mark Sisson Guest

  2. Similar Questions and Discussions

    1. double click causes click-event anddoubleClick-event
      I too am interested in a response to this. I see all kinds of information on how to enable the double-click event, but not how to distinguish...
    2. Getting Error: Event Type 'flash.event:event' is unavailable ?????
      Hi, I am not using Cairngorm or anything, but trying to get an app built first without it then look into it. I am getting this error however...
    3. stumped...table - row - click event, cancel checkbox event
      I have a html table and mutliple rows. On each row i put an onclick event that opesn a modal window and prompts the user for some information. I...
    4. Event Fires after CreateChildControls
      I have created a C# control that creates its objects within CreateChildControls. One of those objects is a button which I have attached to a...
    5. Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl.
      Hello I have the following situation: (everything is dynamic (controls.add)) 1. Button.Init { WasButtonClickFired = true } 2....
  3. #2

    Default Re: CreateChildControls Event before Click Event

    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:
    [url]http://obies.com/vga/blog.aspx[/url]

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

    and not by private mail.
    "Mark Sisson" <mark@corporatedigital.com> wrote in message
    news:88cc4eb9.0307161919.1dee97be@posting.google.c 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.

    Victor Garcia Aprea [MVP] Guest

  4. #3

    Unhappy Re: CreateChildControls Event before Click Event

    I am also facing the same kind of problem. The web part code i am working on has 2 link buttuns and a click event associated to it.
    And on link button click new child controls need to be created which depend on the code body inside the linkbutton event code.
    but since the CreateChildControls() gets fired before the link button click event the logic of functionality is lost and the desired output appears on second click

    Please suggest me what should be done..
    i need to solve this issue as soon as possible!!

    what does recreating controls after link button event mean as suggested in above post?
    how is it done?
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139