user control property

G

Guoqi Zheng

Dear sir,

I have Page Header user control. On my main page, I have the following code.

<uc1:header id="MyHeader" runat="server"
PageName="OurProducts.aspx"></uc1:header>

PageName property is a public variable inside that user control. When I put
the value of PageName inside the html code, everything works ok. However, I
would like to determine the value of PageName by coding. So I do the
following.

public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MyHeader.PageName = "Others.aspx"
End Sub

When I tried to compile the code, I always get an error of Name "MyHeader"
not declared.

Can someone point out what I did wrong here? I am using VS.NET 2003

--
Met vriendelijke groet,

Guoqi Zheng
Tel: +31 (0) 23 5407422
Mob: 0648252520
http://www.meetholland.com
 
G

Guest

In your code-behind, do: protected withevents MyHeader as header, where MyHeader *must* match whatever you use for ID of the instance of the control on your page, and header is the name of the user control class

----- Guoqi Zheng wrote: ----

Dear sir

I have Page Header user control. On my main page, I have the following code

<uc1:header id="MyHeader" runat="server
PageName="OurProducts.aspx"></uc1:header

PageName property is a public variable inside that user control. When I pu
the value of PageName inside the html code, everything works ok. However,
would like to determine the value of PageName by coding. So I do th
following

public Sub Page_Load(ByVal sender As System.Object, ByVal e A
System.EventArgs) Handles MyBase.Loa
MyHeader.PageName = "Others.aspx
End Su

When I tried to compile the code, I always get an error of Name "MyHeader
not declared

Can someone point out what I did wrong here? I am using VS.NET 200

-
Met vriendelijke groet

Guoqi Zhen
Tel: +31 (0) 23 540742
Mob: 064825252
http://www.meetholland.co
 
K

Kevin Spencer

Yo need to declare the header variable in the CodeBehind script if you want
to manipulate it there. Something like:

Protected MyHeader As header

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

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

Ask a Question

Top