日期:2014-05-19  浏览次数:20843 次

帮忙讲讲这个代码好吗 谢谢
public   class   pub:   System.Web.UI.Page
{
public   static   void   Messbox(string   mess,Page   obj){
System.Text.StringBuilder   oStringBuilder   =   new   StringBuilder();
oStringBuilder.Append( " <script   language=javascript> ");
oStringBuilder.Append( "alert( ' ' "+mess+ " ' '); ");
//oStringBuilder.Append( "formyc.reset(); ");
oStringBuilder.Append( " </script> ");
obj.Page.RegisterStartupScript( "reset ",oStringBuilder.ToString());

}

------解决方案--------------------
RegisterStartupScript
向页面写一段脚本

前面都是拼凑的javascript代码
最后写入页面

其实不用传递 page对象也可以

(Page)HttpContext.Current.Handler
------解决方案--------------------
public class pub: System.Web.UI.Page
{
public static void Messbox(string mess,Page obj){
System.Text.StringBuilder oStringBuilder = new StringBuilder();
==========================
声明一个StringBuilder 对象

oStringBuilder.Append( " <script language=javascript> ");
==========================
追加一句话在末尾
oStringBuilder.Append( "alert( ' ' "+mess+ " ' '); ");
==========================
追加一句话在末尾
//oStringBuilder.Append( "formyc.reset(); ");
==========================
追加一句话在末尾
oStringBuilder.Append( " </script> ");
==========================
追加一句话在末尾
obj.Page.RegisterStartupScript( "reset ",oStringBuilder.ToString());
==========================
将StringBuilder 写到客户端,并命名为reset
(这就是给客户端注册脚本)

}

------解决方案--------------------
常用这种方面向页面输出Javascript
------解决方案--------------------
只要你想就叫!