Literals

G

Guest

Hi,

I am just transfering to asp.net from classic asp. I wish to write out a
"<base href=' & servername & '>" dynaically in the head section of the
form.
I though at first a lieral would do the trick and that i could just set the
text of the lieral (which server I am running on) in the page load event.

however I found that I can't place a lieral in the head in the forms
designer of visual studio and even if I could I guess that I would have to
make the <form> elemants of asp.net surround the literal.

does any body please have a solution to my problem.

any help is appreciated.

cheers

martin.
 
M

martin

Thank you all.


CT said:
Hmm, not sure if this will do it for you, but here it goes:

This bit goes in between the head start and end tags:

<base id="serverNameLiteral" href="" runat="server" />

This declaration goes in the class in your code behind file:

protected System.Web.UI.HtmlControls.HtmlGenericControl serverNameLiteral;

This bit goes in the Page_Load event handler in your code behind file:

foreach (System.Web.UI.Control ParentControl in this.Page.Controls)
{
if (ParentControl.GetType().ToString() ==
"System.Web.UI.HtmlControls.HtmlGenericControl")
{
if (ParentControl.ID == "serverNameLiteral")
{
serverNameLiteral.Attributes["HREF"] = servername;
}
}
}

I'm sure it can be done much neater, but it might be what you're after.
--
Carsten Thomsen
http://www.apress.com/book/bookDisplay.html?bID=105
Hi,

I am just transfering to asp.net from classic asp. I wish to write
out
a
"<base href=' & servername & '>" dynaically in the head section of the
form.
I though at first a lieral would do the trick and that i could just set the
text of the lieral (which server I am running on) in the page load event.

however I found that I can't place a lieral in the head in the forms
designer of visual studio and even if I could I guess that I would have to
make the <form> elemants of asp.net surround the literal.

does any body please have a solution to my problem.

any help is appreciated.

cheers

martin.
 

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,007
Latest member
obedient dusk

Latest Threads

Top