Events in dynamically loaded user controls

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?
 
K

Kevin Spencer

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.
 
S

SSW

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top