Events from dynamic web controls

Results 1 to 2 of 2

Thread: Events from dynamic web controls

  1. #1
    Join Date
    Dec 1969

    Default Events from dynamic web controls

    I have problems in understanding the behavior of the events triggered by dynamically created controls over a webform.<BR>Could you help me?<BR><BR>In a webform, I have a static PlaceHolder PH containing a table of controls, dynamically generated. Among these, a linkbutton (LinkBtn) to which have attached a click handler method, LinkBtn_Click(...) .<BR>Generally it works fine, but if in the LinkBtn_Click(...) code I try to access a webform control, even the static PlaceHolder PH, I have a runtime message saying that the control does not exist in the page.<BR><BR>Nevertheless, I have put the procedure that creates the dynamic table of controls in the Page_Load, and from the debugger I see that this method is called before entering the dynamic linkbutton click handler LinkBtn_Click . Until the last instruction of the Page_Load, all the static and dynamic controls have been created and added to the page & placeholder (I see them in the debugger Watch window). As the code enter, as the immediately next step, the LinkBtn_Click lines, all the Page controls disappear (the Page.Controls.Count is zero ).<BR>Why?<BR>On the same webform I have also some static Button(s) and when entering their click handler, all works fine, the table is dynamically geneterated in the correct way and I can access the dynamic controls.<BR><BR>Davide

  2. #2

    Default RE: Events from dynamic web controls

    For events and viewstate to work properly, controls that are added "on the fly" must be added early, before LoadViewState.<BR><BR><BR>

Posting Permissions

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