简体   繁体   English

如何在运行时中创建.aspx页?

[英]How to create .aspx page in Runtime?

I need to create .aspx page at runtime: 我需要在运行时创建.aspx页面:

Say for Ex: 举例来说:

I have a configuration xml file, it has 2 main nodes and each has its subnodes as below: 我有一个配置xml文件,它有2个主要节点,每个都有其子节点,如下所示:

<?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. 当我加载.aspx页面时,我必须读取xml文件节点,并采用“名称”属性并在该页面中创建dropdownlist控件。
  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. 从下拉列表中,如果用户选择“第一个”,则需要遍历子节点并在运行时在同一aspx页面中创建控件。 EX: If the user selects "First" from the drop down, i need to create a Texbox in the page. EX:如果用户从下拉菜单中选择“ First”,则需要在页面中创建一个Texbox。 and If the user selects "Second" from the drop down, i need to create a Textbox and dropdown list as given in the xml. 如果用户从下拉列表中选择“第二”,则需要创建一个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. 反序列化 xml。
  2. Subscribe on DropDownList SelectedIndexChanged event . 订阅DropDownList SelectedIndexChanged 事件
  3. Add code that will add controls to the page dynamicaly . 添加将动态添加控件到页面的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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