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

c#出错。。Response is not available in this context
using   System;
using   System.Data;
using   System.Configuration;
using   System.Web;
using   System.Web.Security;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.WebControls.WebParts;
using   System.Web.UI.HtmlControls;

///   <summary>
///   Summary   description   for   globalfunc
///   </summary>
///  
namespace   globalfunc
{
        public   class   globalfuncc   :   System.Web.UI.Page
        {
                public   void   globalfuncf(ref   int   mm)
                {
                        mm   =   mm   +   1;
                       
                        Response.Write( " <script   language=javascript> alert( "   +   mm.ToString()   +   "); </script> ");////这句出现错误。出错如下。。
                }

        }
}

这是我自定义的一个命名空间。我的本意是将其做为全局的函数来调用。
可是程序一到response.write...这句时就会报错,:Response   is   not   available   in   this   context.这是为何呢?如果在外面定义为一个函数则没有任何问题。我将上面所写的代码放在app_code中。请高手指教。


------解决方案--------------------
学习
------解决方案--------------------
response函数只能在*.aspx.cs中引用得到。。
------解决方案--------------------
string str1 = " <script> alert( ' " + mm.ToString() + " ') </script> ";
Response.Write(str1);
看看
------解决方案--------------------
我也遇到了类似问题,不只搂主解决了么? 我是在一个事件里面写的,也报同样的错,还有 楼上的方法也行不通,到底是为什么会出错呀?
------解决方案--------------------