ASP.NET catching controls from html generated from the database

Posted by Drahcir on Stack Overflow See other posts from Stack Overflow or by Drahcir
Published on 2009-06-12T08:56:04Z Indexed on 2010/03/28 22:03 UTC
Read the original article Hit count: 291

Filed under:

I have a set of websites that basically do the exact same thing in terms of functionality, the only thing that varies is the css and how the html is laid out.

Is there a way to generate the html from a database (ie retreiving the html from a table) and then catching the controls (like buttons, textboxes etc) from the code behind?

UPDATE:

Here is an example of what I want to acheive:

<html>
<div id="generatedContent" runat="server">
<!-- the following content has been generated from the database on the page load event -->
<div>
     This is a textbox <input id="tb1" runat="server" type="text" />
     This is a button <input type="submit" id="btn1" runat="server" value="My Button" />
</div>
</div>
</html>

This is the code behind

var tb1 = new HtmlControls.HtmlInputText();
tb1 = FindControl("tb1");
var btn1 = new New HtmlControls.HtmlInputSubmit();
btn1 = FindControl("btn1");

Now obviously since the html has been generated from the database (ie after the page has already been initialised) the FindControl method will return null.

© Stack Overflow or respective owner

Related posts about ASP.NET