日期:2014-05-18  浏览次数:20395 次

。请问乱码问题:动态创建用户控件后打开出现乱码
某用户控件是用C#代码生成的
1.是一个隐藏input   然后在js把div内容赋给它
    document.form1.hiContent.value   =     document.getElementById( "divContent ").innerHTML  
2.在Cs里面     创建ascx文件
  strPath   =   strRootPath   + "\\TemplateControl\\ "   +   txtTemplateName.Value.Trim()   +   ".ascx ";
                        sw   =   new   StreamWriter(strPath,   false);
                        string   strHead   =   " <%@   Control   Language= 'C# '   AutoEventWireup= 'true '   CodeFile= ' "   +   txtTemplateName.Value.Trim()   +   ".ascx.cs '   Inherits= ' "   +   txtTemplateName.Value.Trim()   +   " '   %> ";
                        sContent   =   strHead   +   " <div> "+hiContent.Value+ " </div> ";
                        sw.Write(sContent);
                        sw.Close();
=======================================================
这样生成后   在电脑上用记事本打开*.ascx是没有乱码的
但是在vs里面打开这个ascx时候,汉字会变成乱码
========================================================



------解决方案--------------------
Encoding是System.Text命名空间下的
------解决方案--------------------
sw = new StreamWriter(strPath,false, Encoding.Utf8);