Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically create server controls?

Status
Not open for further replies.

beaniebear

Programmer
Sep 14, 2001
93
GB
I have a piece of code in ASP that I now want to produce something similar in ASP.net. This is my first project using ASP.net and am looking for a bit of direction as to how best to achieve this (not expecting anyone to write the code for me!)?

The code currently allows the contents of SQL server tables to be maintained. Textboxes are built dynamically by looping through a recordset and pulling back table information and then dynamically building a form based on the number of fields and types in the table. The user selects which table they want to update and the form is automatically built for them. In my asp version I also build javascript to do error chcecking on the input the user types in.

Can the server controls in asp.net be built in this way? Is there a way I can add them to a specific form? And will I still be able to reference them in the code behind?

If there would be a better way to approach this then I am open to suggestions.

Thanks for any advice you can give me, Jo
 
You may consider a editable datagrid or datalist that brings back everything into text boxes...

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Yes, you can dynamically create server controls. Keep in mind that ASP.NET is still just a web app, which means once the server is through generating a page, it "goes away" until it is requested again.

So, every code-path in your code-behind page must re-create the dynamic controls.

This article: ASP.NET Conditional Dynamic Controls discusses the ins and outs of the issues involved.

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top