Jey
Jey

Reputation: 2127

How to create .aspx page in Runtime?

I need to create .aspx page at runtime:

Say for Ex:

I have a configuration xml file, it has 2 main nodes and each has its subnodes as below:

<?xml version="1.0" encoding="utf-8"?>
<Root>
<Options name="First">
    <controls>
        <control type="textbox" lable="Option1TextBox" value="">            
    </controls>
</Options>

<Options name="Second">
    <controls>
        <control type="textbox" lable="Option2TextBox" value="">
        <control type="dropdown" lable="Option2dropdown" value="Value1, Value2">            
    </controls>
</Options>

  1. When i load the .aspx page, i have to read the xml file node and i take the "name" attribute and create the dropdownlist control in the page.
  2. From the dropdownlist, if the user selects the "First" i need to loop through the subnode and create the controls at runtime in the same aspx page. EX: If the user selects "First" from the drop down, i need to create a Texbox in the page. and If the user selects "Second" from the drop down, i need to create a Textbox and dropdown list as given in the xml.

Any suggestion/guide will be highly appreciated.

Upvotes: 0

Views: 649

Answers (2)

user854301
user854301

Reputation: 5493

You need to perform some steps to achive what you want.

  1. Deserialize xml.
  2. Subscribe on DropDownList SelectedIndexChanged event.
  3. Add code that will add controls to the page dynamicaly.

Upvotes: 0

Habib
Habib

Reputation: 223247

Instead of creating an "aspx" page at the run time, you should look into creating User Control for ASP.Net and then adding them at run time according to your need.

Upvotes: 4

Related Questions