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


Question

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

1
45
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">
</div>

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">
    Sys.Application.add_load(MyLoad);
    function MyLoad(sender) {
        $get('<%= div.ClientID %>').innerHTML += " - text added on client";
    }
</script>
81
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
Icon