Professional Web Applications Themes

Event Fires after CreateChildControls - ASP.NET Building Controls

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 command event. The command event fires after CreateChildControls runs, but I want the clicking of the button to have an effect on what items CreateChildControls creates. Is this possible? Obviously I can make this happen by setting a value on an object on the client side and reading it in CreateChildControls. But still, I am curious. -- John Bankhead...

  1. #1

    Default 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 command event. The command event fires after CreateChildControls runs,
    but I want the clicking of the button to have an effect on what items
    CreateChildControls creates. Is this possible? Obviously I can make this
    happen by setting a value on an object on the client side and reading it in
    CreateChildControls. But still, I am curious.


    --
    John Bankhead
    John Bankhead Guest

  2. #2

    Default Re: Event Fires after CreateChildControls

    Hi,

    you could do this in Click event handler (of the Button) or have customized
    routine to do it (assuming we are inside the custom control logic all the
    time)

    a) Clear child controls collection by calling Controls.Clear() and clear
    child state by calling ClearChildViewState()
    b) set ChildControlsCreated to false
    c) Do the stuff that has impact on child control creation
    d) finally call EnsureChildControls which willl call CreateChildControls (it
    does that when ChildControlCreated flag is false)

    So simply saying, you recreate the control in such scenario.

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    [url]http://blogs.aspadvice.com/joteke[/url]



    Teemu Keiski Guest

Similar Threads

  1. CreateChildControls Event before Click Event
    By Mark Sisson in forum ASP.NET Building Controls
    Replies: 2
    Last Post: September 30th, 02:41 PM
  2. Dropdownlist onselectedIndexChanged event not fires
    By Alexander Reichman in forum ASP.NET Web Services
    Replies: 1
    Last Post: November 11th, 12:43 PM
  3. ItemCommand Event fires twice
    By Jonas Nilsson in forum ASP.NET General
    Replies: 3
    Last Post: August 1st, 09:19 AM
  4. asp:textbox_TextChanged event no longer fires???
    By Kathy Burke in forum ASP.NET General
    Replies: 2
    Last Post: July 18th, 02:38 PM
  5. Page Load Event Fires Twice
    By Bob Barrows in forum ASP
    Replies: 6
    Last Post: July 10th, 09:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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