Background
We have a web application to dynamically generate data entry page to allow user to enter data from the database based on the business logic. The application is not quite efficiency as the data entry layout needs to be generated every time when the page is loaded. So we are thinking to create a web custom control use the CodeDom technology. The web custom control will be a lot more efficiency than dynamically generating as the custom control only need to be generated one after the business logic is changed. I created a simple test application using the CodeDom to prove the concept. I now post my work to share with people.
Implementation
The test solution includes two projects. The ControlGenerator is the class library to generate the web customer control. The generatorTest is a web site used to test the generator. It contains two pages, default.aspx has the button “Generate the Assembly” to generate the custom control assembly. Click on this button will generate the assembly to the bin folder of the GeneratorTest site. The page TestPage.aspx used to test the generated control. Click on “Test Page” button in the default page will redirect to the testpage.aspx.
The Generator will generate the custom control as following:
namespace GeneratedAssemblyTest {
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class DataEntry : Control {
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.Write("Title: ");
}
}
}
Run the Test application
The test application is developed with VS2005. Open ControlGenerator.sln with VS2005 and set GeneratorTest as startup project and click on run.
Thursday, January 10, 2008
Subscribe to:
Posts (Atom)