H
hybrid
I have problems in understanding the behavior of the events triggered by
dynamically created controls over a webform.
Could you help me?
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(...) .
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.
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 ).
Why?
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.
Davide
dynamically created controls over a webform.
Could you help me?
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(...) .
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.
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 ).
Why?
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.
Davide