How to dynamically add text to header section in asp.net

I want to add the server name in the section of the page section dynamically, like

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

Can someone please let me know how I can add this tag <!-- DP2-WEB005 -->to the chapter section.

server name I will process it, but I do not know how to add a dynamically commented tag.

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

Hope this helps ... ( link )

UPDATE:

Is this what you want:

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

And here is the conclusion:

<!DOCTYPE html>

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

</title><!-- QWERTY123--></head>
+4
source
<head runat="server">
<%= serverName %>
</head>

In code

public string serverName{get;set;}

protected void Page_Load(object o, EventArgs e)
{
 serverName="assign";
}
+2
source

Aspx:

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

:

PageLoad()

public string Content{get;set;}
protected void Page_Load(object sender, EventArgs e)
{  
  String Content = "Content here";
}
+1

css java- script ,

 var myHtmlLink = new HtmlLink { Href = @"filepath" };
 myHtmlLink.Attributes.Add("rel", "stylesheet");
 myHtmlLink.Attributes.Add("type", "text/css");
 Page.Header.Controls.AddAt("0", myHtmlLink);
+1

Source: https://habr.com/ru/post/1543039/


All Articles