如何在动态创建后加载asp.net页面。 [英] How to load asp.net page after dynamically created.

查看:87
本文介绍了如何在动态创建后加载asp.net页面。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态创建asp.net页面并且它创建得非常好但问题没有在解决方案资源管理器中显示。



这里是我创建动态的代码页面...



i am creating asp.net page dynamically and it is creating very well but the problem is not showing in solution explorer.

here is my code to create dynamic page...

try
            {
                fielName = Server.MapPath("~/Sample.aspx");
                ViewState["Createdpage"] = fielName.ToString();
                //File.Create(fielName);
                //File.AppendText(fielName);


                // create a writer and open the file
                TextWriter tw = new StreamWriter(fielName);

                // write a line of text to the file
                tw.WriteLine(@"<%@ Page Language=""C#"" AutoEventWireup=""true""  CodeFile=""Sample.aspx.cs"" Inherits=""DynamicPages.Sample"" %>

<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">

<html xmlns=""http://www.w3.org/1999/xhtml"">
<head runat=""server"">
    <title></title>
</head>
<body>
    <form id=""form1"" runat=""server"">
    <div>

    </div>
    </form>
</body>
</html>
");

                // close the stream
                tw.Close();


                tw = new StreamWriter(fielName + ".cs");


                // write a line of text to the file
                tw.WriteLine(@"using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace DynamicPages
{
    public partial class Sample : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {


    }
}
}");
                // close the stream
                tw.Close();

                tw = new StreamWriter(fielName + ".designer.cs"); //Default.aspx.designer.cs

                tw.WriteLine(@"namespace DynamicPages {


    public partial class Sample {

        /// <summary>
        /// form1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.HtmlControls.HtmlForm form1;

        /// <summary>
        /// btnAdd control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Button btnAdd;
    }
}");

                // close the stream
                tw.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

推荐答案

正如Ashraff所说您需要打开图标才能看到所有文件,因为它位于驱动器上但未添加到项目中。
As Ashraff said you need to turn on the icon to see all files because it is on the drive but not added to the project.


单击项目在解决方案资源管理器 - > 点击解决方案文件显示所有文件 > - > 现在文件将以白色显示 - > 右单击该文件,然后单击包含在项目中
Click on Project in Solution explorer -> Click Show all files on the menu bar above the Solution File -> Now the file will be displayed in white color -> Right Click on that File and click Include in Project


这篇关于如何在动态创建后加载asp.net页面。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆