我想请教下在窗体设计中,可以通过 
try{}
catch(exeception en)
{messagebox.show(en.message)}这种方法来现实库中存储过程提示的错误如(提示已存在相关记录)
if exists(select * from score where xh=@xh and kch=@kch)
         raiserror ('已存在相关记录',16,1)
         else
             if @xh='' or @kch=0 or @cj<0
                raiserror ('数据不能为空',16,1)
                else
                      insert into score (xh,kch,cj) values (@xh,@kch,@cj)
那在web中有这样的功能吗?如果有怎么写啊

解决方案 »

  1.   

    Response.Write("<script>alert('"+en.message+"')</script>")
      

  2.   


    Page.ClientScript.RegisterStartupScript(this.GetType(), "myjs", "alert('"+en.message+"');", true);
      

  3.   


    这种方法可行,,,一般情况下按钮事件是不是都会引起页面的刷新啊。。(除了用AJAX)
      

  4.   

    在页面注册js脚本,使用上面那句话会在页面的底部生成一段js代码。如果你使用Response.Write,会在页面输出前即在页面的<html><head>的前面输出代码或文字,会影响页面的布局的。
    而使用Page.ClientScript.RegisterStartupScript会在输出的html代码当中注册相应的js脚本,避免上述问题