4

I want to add the server name in my page head section dynamically like

<head>
<!-- DP2-WEB005 -->
</head>

can anyone please let me know how can I add this <!-- DP2-WEB005 --> tag in head section.

server name I will handle it but I don't know how add that commented tag dynamically.

Dhaval Patel
  • 7,315
  • 6
  • 35
  • 68

4 Answers4

4
HtmlGenericControl newControl = new HtmlGenericControl("someTag");
newControl.Attributes["someAttr"] = "some value";
Page.Header.Controls.Add(newControl);

I hope this helps ... (the reference)

UPDATE:

This is that you want :

string serverName = "QWERTY123";
this.Page.Header.Controls.Add(new LiteralControl("<!-- " + serverName + "-->"));

And here is the output :

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title><!-- QWERTY123--></head>
Community
  • 1
  • 1
Saman Gholami
  • 3,241
  • 6
  • 29
  • 67
  • Thanks dude I have already tried it but I want commented tag while in this case it will create a server tag in page – Dhaval Patel Jun 03 '14 at 09:31
2
<head runat="server">
<%= serverName %>
</head>

In code behind

public string serverName{get;set;}

protected void Page_Load(object o, EventArgs e)
{
 serverName="assign";
}
Murali Murugesan
  • 21,923
  • 17
  • 67
  • 118
1

Try like this

Aspx:

   <html>
    <head runat="server">
      <%= Content %>
    </head>
    <body>
      //Code here
    </body>
   </html>

Code Behind:

In Code behind write the following code in PageLoad()

public string Content{get;set;}
protected void Page_Load(object sender, EventArgs e)
{  
  String Content = "Content here";
}
Vignesh Kumar A
  • 26,868
  • 11
  • 59
  • 105
1

If you want to add css or java-script in your page section you can use the following

 var myHtmlLink = new HtmlLink { Href = @"filepath" };
 myHtmlLink.Attributes.Add("rel", "stylesheet");
 myHtmlLink.Attributes.Add("type", "text/css");
 Page.Header.Controls.AddAt("0", myHtmlLink);
शेखर
  • 17,236
  • 13
  • 56
  • 110