如何在asp.net中动态创建一个.aspx页面中 [英] how to create a .aspx page dynamically in asp.net
本文介绍了如何在asp.net中动态创建一个.aspx页面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网页叫做First.aspx在网站上,他的诠释页,我有一个简单的asp.net按钮。
我要的是,在该按钮的单击事件,呈现一个新的动态页面,可以在新窗口或打开什么标签。
我怎样才能做到这一点?
新页面不在网站,当前页创建需要在运行时被创建的,并且需要以动态
解决方案
保护无效的button1_Click(对象发件人,EventArgs的发送)
{ File.Copy(使用Server.Mappath()+\\\\ abc.aspx,(使用Server.Mappath()+\\\\+ TextBox1.Text +的.aspx));
File.Copy(使用Server.Mappath()+\\\\ abc.aspx.cs,(使用Server.Mappath()+\\\\+ TextBox1.Text +.aspx.cs)); //.aspx页 StreamReader的SR =新的StreamReader(使用Server.Mappath()+\\\\+ TextBox1.Text +的.aspx);
字符串fileContent = sr.ReadToEnd();
sr.Close();
使用(StreamWriter的SW =新的StreamWriter(使用Server.Mappath()+\\\\+ TextBox1.Text +的.aspx))
{
fileContent = fileContent.Replace(ABC,TextBox1.Text);
Sw.WriteLine(fileContent);
Sw.Flush();
Sw.Close();
} //.aspx.cs页 的StreamReader SR1 =新的StreamReader(使用Server.Mappath()+\\\\+ TextBox1.Text +.aspx.cs);
字符串fileContent1 = sr1.ReadToEnd();
sr1.Close();
使用(StreamWriter的SW1 =新的StreamWriter(使用Server.Mappath()+\\\\+ TextBox1.Text +.aspx.cs))
{
fileContent1 = fileContent1.Replace(ABC,TextBox1.Text);
Sw1.WriteLine(fileContent1);
Sw1.Flush();
Sw1.Close();
} }
I have one page called First.aspx in website, int his page, I have a simple asp.net button.
What I want is, on the click event of that button, render a new dynamic "page" that can be opened in a new windows or tab.
How can I achieve this?
The new page is not in the website, this page create needs to be created at runtime and needs to be dynamic.
解决方案
protected void Button1_Click(object sender, EventArgs e)
{
File.Copy(Server.MapPath("") + "\\abc.aspx", (Server.MapPath("") + "\\" + TextBox1.Text + ".aspx"));
File.Copy(Server.MapPath("") + "\\abc.aspx.cs", (Server.MapPath("") + "\\" + TextBox1.Text + ".aspx.cs"));
//.aspx Page
StreamReader sr = new StreamReader(Server.MapPath("") + "\\" + TextBox1.Text + ".aspx");
string fileContent = sr.ReadToEnd();
sr.Close();
using (StreamWriter Sw = new StreamWriter(Server.MapPath("") + "\\" + TextBox1.Text + ".aspx"))
{
fileContent = fileContent.Replace("abc", TextBox1.Text);
Sw.WriteLine(fileContent);
Sw.Flush();
Sw.Close();
}
//.aspx.cs Page
StreamReader sr1 = new StreamReader(Server.MapPath("") + "\\" + TextBox1.Text + ".aspx.cs");
string fileContent1 = sr1.ReadToEnd();
sr1.Close();
using (StreamWriter Sw1 = new StreamWriter(Server.MapPath("") + "\\" + TextBox1.Text + ".aspx.cs"))
{
fileContent1 = fileContent1.Replace("abc", TextBox1.Text);
Sw1.WriteLine(fileContent1);
Sw1.Flush();
Sw1.Close();
}
}
这篇关于如何在asp.net中动态创建一个.aspx页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文