Literals

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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.
 
Back
Top