Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 30th, 2006, 03:09 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page Lifecycle

I've got a page called RenewMembership.aspx that has a master page.

The master in turn has a User control on it called MemberPanel.ascx.

The user control has as a public variable (called itsMember) an instance of a class (called Member) that I created globally and stuck in the App_Code directory. The Member class has the following properties:

    Public MemberID As Integer
    Public FirstName As String
    Public LastName As String
    Public DaysToExpiration As Int16
    Public Alerts As Integer

What I want to do is get at the object's MemberID from the RenewMembership.aspx page.

So, in RenewMembership.aspx's Page_Load event handler, I execute this code...

Dim myMemberPanel As MemberPanel = Master.FindControl("MemberPanel1")
lblError.text = myMemberPanel.itsMember.FirstName

I'm successful in creating myMemberPanel, but it keeps returning nothing as its itsMember property.

The Page_Load event handler of the MemberPanel.ascx user control looks like this...

        If Session("Member") = Nothing Then
            Me.lbLogIn.Visible = True
        Else
            itsMember = New Member
            itsMember = itsMember.FromXML(Session("Member"))
            Me.olblWelcome.Text = "Welcome back " & itsMember.FirstName
            Me.olblWelcome.Visible = True
        End If

Obviously I could just populate another Member object in RenewMembership.aspx's Load event, the same way I do in the user control's load event. But I can't bring myself to do this, since there's already one in the user control.

I'm pretty sure this has something to do with the page lifecycle, i.e. the page loads before the User Control does or something like that, but the information on the Internet about the Page lifecycle is too intense for me to delve into right now. Anyone know a short answer?

Thanks.

Aaron

 
Old April 30th, 2006, 03:46 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is a diagram which may be of help...

http://www.datasushi.net/diagram.jpg

Thanks again,

Aaron

 
Old May 1st, 2006, 11:15 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I figured this out.

It was, in fact, the page lifecycle. If you check out

http://weblogs.asp.net/jeff/archive/...04/172683.aspx

it is quite clear that the PageLoad event happens before the ControlLoad event. Booooo! Oh well, I guess all it means is that if I want to do this type of thing I'll have to use a different event of the page. PagePreRender looks pretty good.

Aaron



 
Old May 4th, 2006, 11:13 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, here's an interesting question.

If I put the code that fetches a reference to my user control in the Page.PreRender event handler, it works just fine. However, if I try to reference that control again after a postback, say in response to a button click, that object no longer exists. I can create it again using Master.FindControl, but shouldn't it already be there, since I created the reference in the PageRender event which has already happenned (I declared it in global scope, and initialized it in PageRender)?

Thanks.

Aaron






Similar Threads
Thread Thread Starter Forum Replies Last Post
access C#.Net page as action of calssic ASP page mansharma_s ASP.NET 1.x and 2.0 Application Design 6 January 7th, 2008 10:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.