469,329 Members | 1,451 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

Url / Page Greeting?

I have 10 .aspx pages within my web application and would like to know what
is the best way I can write code within my header user control so that the
greeting message change for each page the user are currently viewing
("should I do an if/else or case statement within my header user control?")?
how?

Also what is the best way to know exactly what page the current user are
viewing ("using the full url such as www.mysite.com/home.aspx or is it a
shorthand way?")?

Example:
Page = www.mysite.com/home.aspx
Greeting.Text = Welcome to mysite.com
Nov 16 '05 #1
4 1217
You could develop a UserControl that exposed a public property such as
GreetingText. When embedding the UserControl on the different physical aspx
pages, you could simply set the getting text by assigning it to the
attribute of the server side control tag.

<CustomerName:GreetingDisplay id="ctrl" runat="server" GreetingText="Here's
ny custom greeting text" />

This is the simple version. You could change the parsing of child controls
for the UserControl, allowing for more customization - e.g. by allowing HTML
content within the opening and closing tags of the server side control tag.

<CustomerName:GreetingDisplay id="ctrl" runat="server">
<div>
<b>Welcome!</b> <br />
<div>Some other text ..</div>
</div>
</CustomerName:GreetingDisplay>

Look for the "ParseChildren" .NET attribute on your UserControl class. The
..NET documentation talks about this attribute and explains how you get
access to the embedded markup within the control tags.

If this doesn't help, please let me know :-)

--
venlig hilsen / with regards
anders borum
--
Nov 16 '05 #2
I already know how to exposing a public variable, but I was thinking doing
it all in the user control was better. However, I'm now thinking exposing
the public variable is the way to go. what do you think?

Example:
*Header.ascx - user control
Public Greeting As String

Public Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

lblGreeting.Text = Greeting

End Sub

-----------------------------------------------------------------------------------------------------------------------------------------------------

*Home.aspx.vb - code behind class

Public ctlHeader As Header

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.ctlHeader.Greeting = "Welcome To MySite.Com"

End Sub

"Anders Borum" <an****@sphereworks.dk> wrote in message
news:uH**************@TK2MSFTNGP10.phx.gbl...
You could develop a UserControl that exposed a public property such as
GreetingText. When embedding the UserControl on the different physical
aspx
pages, you could simply set the getting text by assigning it to the
attribute of the server side control tag.

<CustomerName:GreetingDisplay id="ctrl" runat="server"
GreetingText="Here's
ny custom greeting text" />

This is the simple version. You could change the parsing of child controls
for the UserControl, allowing for more customization - e.g. by allowing
HTML
content within the opening and closing tags of the server side control
tag.

<CustomerName:GreetingDisplay id="ctrl" runat="server">
<div>
<b>Welcome!</b> <br />
<div>Some other text ..</div>
</div>
</CustomerName:GreetingDisplay>

Look for the "ParseChildren" .NET attribute on your UserControl class. The
.NET documentation talks about this attribute and explains how you get
access to the embedded markup within the control tags.

If this doesn't help, please let me know :-)

--
venlig hilsen / with regards
anders borum
--

Nov 16 '05 #3
Hello!

Well, you could keep the greeting text in an Xml file and associate the
different greeting elements with the name of the aspx files. Then, when the
UserControl loads, you simply load up the Xml file in an XmlDocument and
performs an XPath query against the XmlDocument.

If an XmlNode was found, you're off to setting the greeting text. Otherwise
just set the visibility of the UserControl to false or display a standard
greeting.

Don't forget to cache your XmlDocument in the ASP.NET Cache with a
dependency on your Xml file.

This approach is more flexible, as it allows for reuse of greetings across
many aspx pages.

Let me know what you think.

--
venlig hilsen / with regards
anders borum
--
Nov 16 '05 #4
What you did not like the declaring the public variable way? The Xml file
sounds cool, but I will never use the same greeting in two different .aspx
pages. Plus, my header user control contain more than just a greeting
(Header = all navigation links, log-in/log-out, etc) . what do you think now
or do you still believe the xml file way is the best way to go?

"Anders Borum" <an****@sphereworks.dk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello!

Well, you could keep the greeting text in an Xml file and associate the
different greeting elements with the name of the aspx files. Then, when
the
UserControl loads, you simply load up the Xml file in an XmlDocument and
performs an XPath query against the XmlDocument.

If an XmlNode was found, you're off to setting the greeting text.
Otherwise
just set the visibility of the UserControl to false or display a standard
greeting.

Don't forget to cache your XmlDocument in the ASP.NET Cache with a
dependency on your Xml file.

This approach is more flexible, as it allows for reuse of greetings across
many aspx pages.

Let me know what you think.

--
venlig hilsen / with regards
anders borum
--

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by The Bicycling Guitarist | last post: by
2 posts views Thread by Mike | last post: by
2 posts views Thread by John Lau | last post: by
reply views Thread by All-Yours Greetings | last post: by
3 posts views Thread by tkaw220 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.