user control and order of events in page

Discussion in 'ASP .Net Building Controls' started by Joe Iano, Jul 4, 2003.

  1. Joe Iano

    Joe Iano Guest

    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
     
    Joe Iano, Jul 4, 2003
    #1
    1. Advertising

  2. Joe Iano

    Teemu Keiski Guest

    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:


    "Joe Iano" <> wrote in message
    news:...
    > 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
    >
    >
     
    Teemu Keiski, Jul 6, 2003
    #2
    1. Advertising

  3. Joe Iano

    Joe Iano Guest

    Thanks Teemu. I'll take a look.

    "Teemu Keiski" <> wrote in message
    news:ubTy0E$...
    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:


    "Joe Iano" <> wrote in message
    news:...
    > 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
    >
    >
     
    Joe Iano, Jul 7, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    order of events - dynamic checkbox events

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Aug 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    577
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Aug 17, 2005
  2. Tony Cheng
    Replies:
    1
    Views:
    8,256
    Juan T. Llibre
    Feb 24, 2006
  3. cmay
    Replies:
    1
    Views:
    798
    bruce barker \(sqlwork.com\)
    Jun 30, 2006
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    387
    Chris
    Aug 30, 2005
  5. Replies:
    1
    Views:
    162
    Peter Michaux
    Apr 27, 2007
Loading...

Share This Page