我在做一个html在线编辑器时,在aspx文件里把所有增加的控件都放到一个iframe里,然后通过文本框id为myhtml取到要存到html文件里的字符串,在点击保存按钮的时候,启动Bsave_ServerClick,进行后台程序来写,可是这样做,当写好并生成html文件以后,aspx页面就立刻刷新了,编辑时放入的空间都没有了,我该如何处理,才能使保存后页面保持不变,还可以继续增加新控件,继续编辑?
C#后台程序主要部分如下:
public void Bsave_ServerClick(object sender, EventArgs e)
    {
string dhtml=myhtml.Value;
string mypath = txtpath.Value;
        string Filename = filename.Value;//动态的文件名
Create_html(mypath + Filename, dhtml);

public void Create_html(string allfilename, string htmlcode)
    {
        FileStream CreateFile = new FileStream(allfilename, FileMode.Create, FileAccess.ReadWrite);
        StreamWriter sw = new StreamWriter(CreateFile);
        sw.WriteLine(htmlcode);//将拼好的Html代码写入页面中
        sw.Close();
    }

解决方案 »

  1.   

    提交前把html放在一个hidden中.客端的document load时,从hhiden中取值到iframe中.
      

  2.   

    “然后通过文本框id为myhtml取到要存到html文件里的字符串”
    这一句应该详细地改为:然后“<html><head>……”+iframe.innerhtml即为要存到html文件里的字符串,通过id为myhtml的文本框的value来取到它。
      

  3.   

    hidden不用了.在你写个function window.onload()
    {
        document.getElementById("iframe1").document.write(document.getElementById("myhtml").value);
    }