简体   繁体   中英

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.

与其在运行时创建“ aspx”页,不如考虑为ASP.Net创建用户控件 ,然后根据需要在运行时添加它们。

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM