How to modify User Control attribute at run-time?

K

Kent P. Iler

Hi,

I created a user control to contain all my navigation items for the website.
I have a title in the nav bar that I set with an attribute in the tag
structure in the ASPX file where I'm using the control. Here's snippets
from the aspx file:

<%@ Register TagPrefix="uc1" TagName="left_nav" Src="left_nav.ascx" %>

Here's where I specify the label text (the PageLabel attribute):
<uc1:left_nav id="Left_nav1" runat="server" PageLabel="Send
e-Mail"></uc1:left_nav>

Inside the user control's ASCX page, I have this for displaying the label:
<asp:Label id="lblPageLabel" runat="server"></asp:Label>

Then, in the codebehind part of the user control, I have this:
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
If (PageLabel <> String.Empty) Then
Me.lblPageLabel.Text = MyPageLabel
End If
End Sub

There is are property routines for PageLabel that sets MyPageLabel =
PageLabel.

Is there a way I can have my ASPX page that includes this user control
overwrite the PageLabel attribute? On certain pages, I'll display something
based on passed-in values or values from a database.

Thanks.

-- Kent Iler
 
J

James Williams

Hello,

You know how when you drop a Label onto a form, the code behind
automatically adds a line like this:
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

Well, you need to manually add your user control, e.g.:
Protected WithEvents Left_nav1 As left_nav

Then you can access it's public properties, e.g.:
Left_nav1.PageLabel

Hope that helps.

-James
 
K

Kent P. Iler

Great! I'll try it out.

Thanks.

--Kent


James Williams said:
Hello,

You know how when you drop a Label onto a form, the code behind
automatically adds a line like this:
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

Well, you need to manually add your user control, e.g.:
Protected WithEvents Left_nav1 As left_nav

Then you can access it's public properties, e.g.:
Left_nav1.PageLabel

Hope that helps.

-James
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top