在页面中, try...catch中, 可以用RegisterStartupScript产生一个对话框, 显示出现的错误或者其他信息, 为什么在类中,怎么也找不到这个方法呢, 我已经把页面中命名空间全给加进来了, 是怎么回事呀, 是在类中, 不能用, 还是我丢了什么东西呀?
如果在类中, 不能使用这种方式,那用什么方法向用户直观提示错误呀?
谢谢各位。

解决方案 »

  1.   

    public static void Show( string sMessage )
    {

                // If this is the first time a page has called this method then
                string locMsg = ResourceReader.readMsg(sMessage);
    if( !m_executingPages.Contains( HttpContext.Current.Handler ) )
    {
    // Attempt to cast HttpHandler as a Page.
    Page executingPage = HttpContext.Current.Handler as Page; if( executingPage != null )
    {
    // Create a Queue to hold one or more messages.
    Queue messageQueue = new Queue(); // Add our message to the Queue
                                            messageQueue.Enqueue(locMsg); // Add our message queue to the hash table. Use our page reference
    // (IHttpHandler) as the key.
    m_executingPages.Add( HttpContext.Current.Handler, messageQueue ); // Wire up Unload event so that we can inject 
    // some JavaScript for the alerts.
    executingPage.Unload += new EventHandler( ExecutingPage_Unload );
    }   
    }
    else
    {
    // If were here then the method has allready been 
    // called from the executing Page.
    // We have allready created a message queue and stored a
    // reference to it in our hastable. 
    Queue queue = (Queue) m_executingPages[ HttpContext.Current.Handler ]; // Add our message to the Queue
                    queue.Enqueue(locMsg);
    }
    }
      

  2.   

    你自己写的类文件,不是继承自system.web.ui.page,所以类不具有RegisterStartupScript方法
      

  3.   

    在类中弹出提示框不太好 最好是在页面文件中捕获异常 再通过脚本显示异常的文本内容
    非要在类中实现也可以这样写
    System.Web.HttpContext.Current.Response.Write("<script language=javascript>alert('"+ex.Message+"');</script>");
      

  4.   

    还要注意 ex.Message中的一些字符 如单引号 要先转义 不然会出脚本错误
      

  5.   

    truelove12(结贴者寥寥无几,心寒ing...) ( ) 信誉:99  2007-08-09 08:05:09  得分: 0  
     
     
       你自己写的类文件,不是继承自system.web.ui.page,所以类不具有RegisterStartupScript方法
    ==========================================
    正解