iframe不显示动态生成的html文件

时间:2012-07-07 15:29:22

标签: html iframe

我正在使用HTMLTEXTWRITER动态创建HTML文件,我可以在浏览器中查看它但是当我尝试在iframe中查看此html时,没有显示任何内容!动态生成htmls的错误是什么? iframe也没有在firefox中显示一些HTML,这就是我创建html的方式:

static string GetDivElements()
    {
        // Initialize StringWriter instance.
        StringWriter stringWriter = new StringWriter();

        // Put HtmlTextWriter in using block because it needs to call Dispose.
        using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
        {
            // Loop over some strings.
            foreach (var word in _words)
            {
                // Some strings for the attributes.
                string classValue = "ClassName";
                string urlValue = "http://www.dotnetperls.com/";
                string imageValue = "image.jpg";

                // The important part:
                writer.AddAttribute(HtmlTextWriterAttribute.Class, classValue);
                writer.RenderBeginTag(HtmlTextWriterTag.Div); // Begin #1
...my html
                writer.RenderBeginTag(HtmlTextWriterTag.Img); // Begin #3
                writer.RenderEndTag(); // End #3

                writer.Write(word);

                writer.RenderEndTag(); // End #2
                writer.RenderEndTag(); // End #1
            }
        }
        // Return the result.

        string pre = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
        pre += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head>";
        pre += "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"><title></title></head><body>";

        return stringWriter.ToString();// +"</body></html>";
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        using (StreamWriter outfile =
        new StreamWriter(@"d:\myFile.htm"))
        {
            outfile.Write(GetDivElements());
        }
    }

0 个答案:

没有答案