user control and order of events in page

J

Joe Iano

Pease be excuse the poorly phrased question. I'm a bit confused:

I've got a user control that accepts username and password values submitted
from a form and authenticates the user. Originally, the control also
performed the response.redirect to the FormsAuthentication.GetRedirectUrl
when the authentication was successful. Now I want to return to the login
page, and let the page decide where to go next, possibly to the
GetRedirectUrl, possibly not.

The problem I'm having is that the user control doesn't complete it's
authentication until after the page's Page_Load event is finished, so it
seems too late to pick up with any additional steps in the page code. The
user control processes the submission in its own function 'public void
SignInForm_Click( Object sender, EventArgs e )' which is fired by the
OnClick event in the form's submit button.

Basically the sequence of events looks like:
start Page_Load()
load user control
finish Page_Load()
start SignInForm_Click() (this is inside the user control)
authenticate credentials
finish SignInForm_Click()
I want to do something in the page here...

Am I making sense? Can anyone explain how to have the user control do its
postback processing work, but then return control to the page for next
steps. Thanks. Joe
 
T

Teemu Keiski

Hi,

one way could be declaring public, custom event in the user control. That
event could be raised on SignInForm_Click method after authenticating has
been done. Page then can have a handler for this event which is run when the
event is fired on the user control. That way Page "can know" that the user
control has done the task.

Say you have event declared in the user control (at class level)
***
Public Event UserAuthenticated As EventHandler
***
Then on the SignInForm_Click() :
***
Sub SignInForm_Click(...)
'Authenticating
RaiseEvent UserAuthenticated(Me,EventArgs.Empty)
End Sub
***

Page can then have event handler for the UserAuthenticated event. Say user
control is declared with ID "myAuth" on the ASPX page.

***
Public Sub myAuth_UserAuthenticated(sender As Object,e As EventArgs) Handles
myAuth.UserAUthenticated
'When this runs user control has done the authentication
End Sub
***

But if you want to send custom data from the user control to the Page (to
determine what to do with the authentication results), you would need to
declare your own event arguments and pass them to the event when it is
raised. Most clear would probably be declaring your own event (other type
than EventHandler that takes only args of type EventArgs i.e no custom data)

Consult the Framework documentation for further details. Events are well
covered there and the concept works with Page and user controls as well.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
(e-mail address removed)
 
J

Joe Iano

Thanks Teemu. I'll take a look.

Hi,

one way could be declaring public, custom event in the user control. That
event could be raised on SignInForm_Click method after authenticating has
been done. Page then can have a handler for this event which is run when the
event is fired on the user control. That way Page "can know" that the user
control has done the task.

Say you have event declared in the user control (at class level)
***
Public Event UserAuthenticated As EventHandler
***
Then on the SignInForm_Click() :
***
Sub SignInForm_Click(...)
'Authenticating
RaiseEvent UserAuthenticated(Me,EventArgs.Empty)
End Sub
***

Page can then have event handler for the UserAuthenticated event. Say user
control is declared with ID "myAuth" on the ASPX page.

***
Public Sub myAuth_UserAuthenticated(sender As Object,e As EventArgs) Handles
myAuth.UserAUthenticated
'When this runs user control has done the authentication
End Sub
***

But if you want to send custom data from the user control to the Page (to
determine what to do with the authentication results), you would need to
declare your own event arguments and pass them to the event when it is
raised. Most clear would probably be declaring your own event (other type
than EventHandler that takes only args of type EventArgs i.e no custom data)

Consult the Framework documentation for further details. Events are well
covered there and the concept works with Page and user controls as well.

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
(e-mail address removed)
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top