Pregunta

We have got several asp .net web forms page with a body tag in it. I want to add an HtmlImage tag just before the body tag finishes for all those pages. So for example - after doing that the code should look like this:

<body>

<img class="imgClass" id="imgID" src="someSource">
</body>

And the c# class that I need to do this is not code behind of an aspx file. But it does extends the class Page. Can somebody tell as to how to do that? I know the jQuery way but not from C# code. Also this is a sort of common code that will be called when any aspx page loads so a general solution will be good. That is why we don't have any ID for body tag.

¿Fue útil?

Solución

You need to have a panel inside your body and give it some id.

<body>
    <asp:Panel id="panel_holder" runat="server">
    </asp:Panel>
</body>

and then in code behind

        HtmlGenericControl div = new HtmlGenericControl("img");
        div.Attributes.Add("src", "image_location");
        panel_holder.Controls.Add(div);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top