Can I dynamically add HTML within a div tag from C# on load event?


Mind you, I am using master pages, but can I locate a div within the page and throw some html in there? Thanks.

6/9/2009 7:35:31 PM

Accepted Answer

You can add a div with runat="server" to the page:

<div runat="server" id="myDiv">

and then set its InnerHtml property from the code-behind:

myDiv.InnerHtml = "your html here";

If you want to modify the DIV's contents on the client side, then you can use javascript code similar to this:

<script type="text/javascript">
    function MyLoad(sender) {
        $get('<%= div.ClientID %>').innerHTML += " - text added on client";
1/21/2009 10:06:11 PM

Use asp:Panel for that. It translates into a div.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow