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:
    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. Advertisements

  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:
     
    Teemu Keiski, Jul 6, 2003
    #2
    1. Advertisements

  3. Joe Iano

    Joe Iano Guest

    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:
     
    Joe Iano, Jul 7, 2003
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.