Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > user control and order of events in page

Reply
Thread Tools

user control and order of events in page

 
 
Joe Iano
Guest
Posts: n/a
 
      07-04-2003
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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      07-06-2003
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:
http://www.velocityreviews.com/forums/(E-Mail Removed)

"Joe Iano" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Joe Iano
Guest
Posts: n/a
 
      07-07-2003
Thanks Teemu. I'll take a look.

"Teemu Keiski" <(E-Mail Removed)> wrote in message
news:ubTy0E$(E-Mail Removed)...
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 Removed)

"Joe Iano" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Differentiate between user caused events and script generated events jmpinchot@gmail.com Javascript 1 04-27-2007 03:05 AM
Order of events: Page_Load in page and base page? cmay ASP .Net 1 06-29-2006 11:26 PM
Sequence Order between Page Init and User Control Init Tony Cheng ASP .Net 1 02-24-2006 01:56 PM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
order of events - dynamic checkbox events =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?= ASP .Net 0 08-17-2005 10:36 PM



Advertisments