How would I go about finding on my ASPX page (from codebehind) and then adding the attribute “runat=server” to it?
I have tried using Page.header.attributes.add(...) and(HtmlHead) Page.FindControl("head"); The second one obviously won’t work as the Head tag doesnt have an ID.
I can’t work out how to change this property and I can’t change or add any additional code to the ASPX page – like ID’s etc.
Unfortunately, this is not possible.
The
runat="server"attribute allows the code behind to “see” the element it decorates. If that attribute is not present in the page markup, the element will not be accessible from code behind and you will not be able to manipulate it.The only way to achieve what you want is to add
runat="server"(and possibly anIDattribute) to the element in the page markup. Only then will you be able to add other attributes, event handlers, etc. from the code behind.