日期:2014-05-20  浏览次数:20392 次

做html在线编辑器时通过C#后台程序在服务端上保存html文件时的问题
我在做一个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();
        }

------解决方案--------------------
提交前把html放在一个hidden中. 客端的document load时,从hhiden中取值到iframe中.
------解决方案--------------------
hidden不用了. 在 你写个 function window.onload() { document.getElementById( "iframe1 ").document.write(document.getElementById( "myhtml ").value); }