?
Solved

Why put a login form in the master page when the content page renders first in the page lifecycle?

Posted on 2010-11-09
8
Medium Priority
?
681 Views
Last Modified: 2012-05-10
I have a simple application where the user can login and see previously submitted applications. I have the login form in my master page, and the form that displays previous applications in my content page. When the user logs in, logically the master page should authenticate them and then the content page, which uses a session variable created during authentication, should populate the form. However I was reading this page: http://msdn.microsoft.com/en-us/library/dct97kc3.aspx which I believe states that the content page does its VB processing before the master page does. That actually makes sense because in my application my form doesn't populate immediately after I login - rather I have to refresh the page first and then it populates. During debugging, my suspicions were confirmed by the fact that the content page VB processes before the master page.

My question is, is there a way to tell the master page VB to go before the content page VB?
0
Comment
Question by:CitySec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 34096123
Don't think so but what you mean by "populate form"? Are you using any databound controls?
I think you might want to rebind those controls after successful login.
0
 
LVL 11

Expert Comment

by:Kelvin McDaniel
ID: 34096153
No, as far as I'm aware there's no way to re-order the page lifecycle.

I'd suggest you use the PreRender page event to handle the processing you're looking for or go with guru_sami's suggestion.
0
 
LVL 2

Author Comment

by:CitySec
ID: 34096181
I'm manually binding form controls to a database. I actually am rebinding the controls after a successful login. The problem is, I have to do a double page refresh to get the form to bind. This is because of the sequence of evens happening during my page life cycle, which is:

1) Content page load (form data binding based on session variable)
2) Master page load (session variable created here)
3) Content control load
4) Master page control load

As you can see, 1) and 2) need to be swapped. Is there another event I can use besides page load?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 41

Expert Comment

by:guru_sami
ID: 34096223
Ok how are you setting forms authentication cookie?
May be we want to see some code...
0
 
LVL 2

Author Comment

by:CitySec
ID: 34096929
I'm not, I'm actually using a session variable instead.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 34097152
Can we see some code?
0
 
LVL 2

Author Comment

by:CitySec
ID: 34097436
Here is the master page. User clicks button to login:

    Private Sub btnLoginSubmit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnLoginSubmit.Click
        Dim u As String = txtUsername.Text
        Dim p As String = txtPassword.Text

        authenticate("in", u, p, "", "")

    End Sub

    Public Sub authenticate(ByVal action As String, ByVal u As String, ByVal p As String, ByVal msg As String, ByVal err As String)
        lblGeneralError.Text = ""
        If action = "out" Then 'when the user logs out
            pnlLoggedOut.Visible = True
            pnlLoggedIn.Visible = False
            lblUserInfo.Text = ""
            lblLogin.Text = "Login"
            Session("userID") = 0
            Session("username") = ""
            Session("password") = ""
            lblGeneralError.Text = err
        ElseIf action = "in" Then 'when the user logs in
            Dim ds As DataSet = clsData.sqlLogin(u, p)
            If ds.Tables(0).Rows.Count > 0 Then
                Dim userID As Integer = ds.Tables(0).Rows(0)(0)
                Dim userEmail As String = ds.Tables(0).Rows(0)(3)
                Dim userCreated As String = CStr(ds.Tables(0).Rows(0)(4))
                Session("userID") = userID
                Session("username") = u
                Session("password") = p
                lblUserInfo.Text = "You are currently logged in as " & userEmail & "."
                lblLogin.Text = "Logout"
                pnlLoggedIn.Visible = True
                pnlLoggedOut.Visible = False
            Else
                authenticate("out", "", "", "", "We could not find your account. Please try again »")
            End If
        ElseIf action = "none" Then 'any time the user is not logging in or out
            If u = "" Or p = "" Then 'user is not logged in
                authenticate("out", "", "", "", "")
            Else 'user is logged in
                'do nothing
            End If
        End If

Here is the code to populate the form fields from the content page. You will see it requires a session variable of "userID" in order to populate.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        requestApp()
    End Sub

    Public Sub requestApp()
        'when a user logs in, we need to find a previously started app id
        'if there are no apps for this user, nothing will happen
        Dim appID As Integer = Session("appID")
        Dim userID As Integer = Session("userID")

        If appID <> 0 And userID <> 0 Then 'one previously started app found
            populateApp(appID)
        ElseIf userID <> 0 Then 'more than one previously started app found
            getSavedApps(userID)
        Else 'no previously started apps found
            'do nothing
        End If
    End Sub

I want the authenticate function on the master page to run before the requestApp function on the content page.
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 34097721
Ok i see...What you will have to do is ...
1: Create an Event in MasterPage
2: Raise this event from MasterPage after your Authentication if it was successful
3: Add event handler to this event in your ContentPage
4: Call requestApp() method from the event handler

Check this out:
http://dotnetslackers.com/Events/re-23154_Capture_Master_Page_Events_in_Content_Pages_ASP_NET_2_0.aspx

Here is a video link which "might" help but the server seems to be down currently:
http://www.asp.net/general/videos/how-do-i-handle-events-in-master-and-content-pages

0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question