[RESOLVED] access div from code behind

I am dynamically creating div tags in my code behind and adding code into the innerHTML property of the div tag and then rendering out the html to replace values inside of a table structure that I have, I then place all the table code onto the page.  I want to be able to access the div tags again from the code behind, but can't seem to because well obviously they aren't set to runat="server".  Is there any way to do this or to set them so they can runat server.



I want to be able to access the div tags again from the code behind

Add div to a panel control or any other container control. Then,you can use FindControl to access div on page postbacks

using System.Web.UI.HtmlControls;
HtmlGenericControl div = new HtmlGenericControl("div");
div.InnerHtml = "<b> Test Message </b>";
div.ID = "div1";

Make sure that dynamic controls are recreated on page postbacks and you can access the div as


Thanks for the information, so I have a string coming from the database "<table><tr><td>AREA1</td><td>AREA2</td</tr></table>"

I want to create one div tag to go in each area. This is where I'm having the most problem.  The number of areas in the string could be different, so I'm looping through each one area and adding a div tag, the div tag has some other code in it to play a flash file.  On some event I want to change the innerHTML of the div tag I created to display a different flash file, but can't seem to find the div tag from the code behind.  Currently I'm using the div.RenderControl to render the div tag into html to insert into the <table> string that is pulled from the database. 

I see you are adding the control, but I don't have a panel to add the control to because I have to insert it into the html string coming from the database.

any other ideas?

What I was thinking was there is no need for you to actually access div on the codebehind...because you are dynamically creating the div...which needs to be created on every postback....so when a postback occurs, you set the new value in the div and then display it....

Hope this solves your problem....


I ended up using iframes surrounded by UpdatePanels to get individual areas of the page to reload. 

Thanks to everyone for the input.

1 thoughts on "[RESOLVED] access div from code behind"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>