ASCX或ASP.net文件可以保存为HTML文件 [英] Can ASCX or ASP.net files be saved as HTML files
本文介绍了ASCX或ASP.net文件可以保存为HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ASCX或ASP.net文件可以保存为HTML文件吗?如果是这样,怎么样?
Can ASCX or ASP.net files be saved as HTML files? if so, how?
推荐答案
您可以直接使用 Render
页面的方法
或 UserControl
。由于该方法受到保护,因此您需要创建一个控制子类。从那里开始,您可以随心所欲地做任何事情。
You can do this directly with the Render
method of a Page
or UserControl
. Since the method is protected, you will need to create a control that subclasses either. From there, you've got access to do whatever you need.
例如
e.g.
public partial class MyPage: Page
{
public string GetPageContents()
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
using (HtmlTextWriter writer = new HtmlTextWriter(sw))
{
Render(writer);
}
return sb.ToString();
}
}
您可能不希望在此之前尽管这个页面的 PreRenderComplete
事件,否则你不能确定所有的子控件/事件/等已经完成。
You probably wouldn't want to call this anytime before the PreRenderComplete
event of the page though, since otherwise you can't be sure all child controls/events/etc have finished.
这篇关于ASCX或ASP.net文件可以保存为HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文