The problem is that you have not declared your label in the Header control.
Try this...
Public Class Header
Inherits System.Web.UI.UserControl
Protected lblHeading as System.Web.UI.WebControls.Label
Private Sub Page_Load(....) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Public Property PageTitle() As String
Get
Return lblHeading.Text
End Get
Set(ByVal Value As String)
lblHeading.Text = Value
End Set
End Property
End Class
HTH,
Dean Fiala
-----------------------------
Very Practical Software, Inc.
http://www.vpsw.com/links.aspx
-----Original Message-----
From: Faisel Y! [mailto:[EMAIL PROTECTED]
Sent: Friday, August 20, 2004 12:20 AM
To: [EMAIL PROTECTED]
Subject: [AspNetAnyQuestionIsOk] Accessing user control's properties
Hi Fiala,
Please find the code here. Thanks for your effort.
Faisel
-=-=-=-[ Header.ascx.vb ]=-=-=-=-
Public Class Header
Inherits System.Web.UI.UserControl
Private Sub Page_Load(....) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Public Property PageTitle() As String
Get
Return lblHeading.Text
End Get
Set(ByVal Value As String)
lblHeading.Text = Value
End Set
End Property
End Class
-=-=-=-[Main Page: HTML (WebForm2.aspx)]=-=-=-=-
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb"
Inherits="SampleApp.WebForm2"%>
<%@ Register TagPrefix="uc1" TagName="Header" Src="Header.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm2</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<uc1:Header id="uCtlHeader" runat="server"></uc1:Header>
</form>
</body>
</HTML>
=-=-=-=-[Main Page: WebForm2.aspx.vb]=-=-=-=-
Public Class WebForm2
Inherits System.Web.UI.Page
Private uCtlHeader As Header
Private Sub Page_Load(....) Handles MyBase.Load
'Put user code to initialize the page here
uCtlHeader.PageTitle = "This is the heading"
End Sub
End Class
=-=-=-=-[This the err: ]=-=-=-=
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 24: 'Put user code to initialize the page here
Line 25:
Line 26: uCtlHeader.PageTitle = "This is the heading"
Line 27:
Line 28: End Sub
Source File: c:\inetpub\wwwroot\SampleApp\WebForm2.aspx.vb Line: 26
> Message: 7
> Date: Thu, 19 Aug 2004 00:15:14 -0400
> From: "Dean Fiala" <[EMAIL PROTECTED]>
> Subject: RE: Accessing user control's properties
>
> Please post all your code and the html for the page.
>
> -----Original Message-----
> From: Faisel Y! [mailto:[EMAIL PROTECTED]
> Sent: Thursday, August 19, 2004 12:09 AM
> To: [EMAIL PROTECTED]
> Subject: [AspNetAnyQuestionIsOk] Accessing user control's properties
>
>
> Hi Fiala
>
> I tried that, but the same err "Obj ref not set ...." Here is what I did
in
> the main page:
>
> Private uCtlHeader As Header
> Private Sub Page_Load(........) Handles MyBase.Load
>
> uCtlHeader.PageTitle = "This is the heading"
>
> End Sub
>
> Please help.
>
> THanks,
> Faisel
>
> Message: 18
> Date: Wed, 18 Aug 2004 07:55:47 -0400
> From: "Dean Fiala" <[EMAIL PROTECTED]>
> Subject: RE: Accessing user control's properties
>
> The control already exists on the page. You just need to create a
reference
> to the control, not try and create a new control.
>
> Delcare a reference to the control at the page level using the ID you
> assigned in the HTML:
>
> Private uCtlHeader as Header
>
> Then you can reference it from any method on your page.
>
> uCtlHeader.PageTitle = "This is the heading"
>
> HTH,
>
> Dean Fiala
>
>
> -----Original Message-----
> From: Faisel Y! [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, August 17, 2004 11:58 PM
> To: [EMAIL PROTECTED]
> Subject: [AspNetAnyQuestionIsOk] Accessing user control's properties
>
>
> I've created a user control Header which is a header with a page title. I
> want to set the page title from code, so I've made it a property:
>
> Public Property PageTitle() As String
> Get
> Return lblHeading.Text
> End Get
> Set(ByVal Value As String)
> lblHeading.Text = Value
> End Set
> End Property
>
> In the main page, I've dragged and dropped the user control on to my page,
> I've created the control in my code-behind:
>
> Dim C1 As NEW Header
> C1.PageTitle = "This is the heading"
>
> However, this is giving me an error: "Object reference not set to an
> instance of an object"
>
> I'm sure the name is right, so what I am missing. Here's the HTML where
the
> control is added:
>
> <uc1:Header id="uCtlHeader" runat="server"></uc1:Header>
>
> I've tried
> "Dim c1 As Header = New Header"
>
> but that didn't work either.
>
> Please help me..
>
> Thanks,
> Faisel
Yahoo! Groups Links
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/