Reputation: 7601
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.
Upvotes: 4
Views: 6460
Reputation: 3512
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>
Upvotes: 4
Reputation: 17604
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);
Upvotes: 1
Reputation: 22619
<head runat="server">
<%= serverName %>
</head>
In code behind
public string serverName{get;set;}
protected void Page_Load(object o, EventArgs e)
{
serverName="assign";
}
Upvotes: 2
Reputation: 28423
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";
}
Upvotes: 1