inserting analytics code with asp.net into page
I have about 50 sites that currently use a template code base to run. There are 3 master pages in the site and when we built them we didn't think to put a literal control on the page to plug in the site's google analytics code. Now I have to add the analytics code right before the closing body tag of the page and if I add a literal to the master page and push it to the 开发者_Python百科web sites it will overwrite all the customizing that we've done on those sites. So, rather than changing the master page.aspx, I'd like to just write it to the page from the code behind if possible, but I can't figure out how. I've seen using the ClientScript to register javascript on the page, but is there a way to programmatically insert a literal as the last control on the page and set it's content to the analytics code? Thanks.
You can use the HtmlGenericControl
:
http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlgenericcontrol(v=VS.80).aspx
Use the InnerHtml
property to inject your HTML.
精彩评论