Events in dynamically loaded user controls

  • Thread starter Thread starter Danny Bloodworth
  • Start date Start date
D

Danny Bloodworth

I have a usercontrol (login.ascx) that is very simple. It accepts
input through two textboxes, and then the user clicks an Imagebutton
to submit.

I have a parent form that checks the page security (security level
needed) against current user security (stored in the context object)
and

if user security >= level needed to view page then
dynamically loads a content control and displays content
else
dynamically loads the login control
end if

The problem is that when I dynamically load the login control (into an
HTML table cell BTW), the ImageButton_Click event will not fire. It
simply posts the page back to the browser.

I've spent the entire day reading newsgroup posts about things like
eventbubbling, adding handlers, etc., but so far I just don't get it.

Can someone give me a "VB" answer to allowing the login control's
imagebutton event to fire?
 
In ASP.Net, you're working in a Stateless environment, which means that
State maintenance is handled through some rather complex workarounds. Each
PostBack of a WebForm is a fresh Request to the server, which has no memory
of the last Request. Each time the Page posts back, the classes in it must
be created anew. Therefore, if you dynamically add a control to a Page, and
expect to handle an event fired by the Page on the client, you must
re-create the control prior to the event handler's handling of the event
after the PostBack.

--
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Kevin Spencer said:
In ASP.Net, you're working in a Stateless environment, which means that
State maintenance is handled through some rather complex workarounds. Each
PostBack of a WebForm is a fresh Request to the server, which has no memory
of the last Request. Each time the Page posts back, the classes in it must
be created anew. Therefore, if you dynamically add a control to a Page, and
expect to handle an event fired by the Page on the client, you must
re-create the control prior to the event handler's handling of the event
after the PostBack.

--
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top