如何在消息框中显示错误消息? [英] how to display a error message in a message box?

查看:84
本文介绍了如何在消息框中显示错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有这样的捕获块

 捕获(SqlException ex)
           {
             lblmsg.Text = ex.Message.ToString();

           } 


但是我想在消息框中显示此消息...,我尝试了此代码,但它不起作用..
任何帮助将不胜感激..



 捕获(以前的SqlException)
 {
    字符串 Msgscript = "  + ex.Message + " ;
 如果(!Page.IsStartupScriptRegistered(" 跨度>))
 {
 Page.ClientScript.RegisterStartupScript(" ,Msgscript);
  }
} 

解决方案

引用:
一个简单的ASP.NET服务器控件:消息框&确认框 [ ^ ]
ASP.NET中的简单MessageBox功能 [用于ASP.NET网站的类似于MessageBox的Windows窗体 [ ^ ]

在asp.net中确认消息框 [ ASP.NET消息框 [ CodeProject 上的搜索结果[ ^ ]和 Response.Write("脚本 /script



祝您好运.


您的字符串缺少标签&逗号

 字符串 Msgscript = "  + ex.Message +  ');</script> ";

如果(!Page.IsStartupScriptRegistered(" 跨度>))
 {
 Page.ClientScript.RegisterStartupScript( .GetType(),"  myErrorScript",Msgscript);

} 


hi

i have catch block like this

catch (SqlException ex)
           {
             lblmsg.Text = ex.Message.ToString();

           }


but i want to display this message in message box ..., i tried this code it is not working..
Any help will be appreciated..



catch (SqlException ex)
 { 
    string Msgscript = "<script>alert('" + ex.Message + "')/script>";    
 if (!Page.IsStartupScriptRegistered("myErrorScript"))    
 {         
 Page.ClientScript.RegisterStartupScript("myErrorScript", Msgscript);   
  } 
} 

Refer:
A Simple ASP.NET Server Control: Message Box & Confirmation Box[^]
Simple MessageBox functionality in ASP.NET[^]
A Windows Form like MessageBox for ASP.NET Website[^]

Confirm message box in asp.net[^]
ASP.NET MessageBox[^]

Search results on CodeProject[^] and google[^]


hi shashavali

once try this

Response.Write("<script>alert('"+ Server.HtmlEncode(ex.Message) + "')</script>");



Best of luck.


Your string is missing tag & comma

string Msgscript = "<script>alert('" + ex.Message + "');</script>";

if (!Page.IsStartupScriptRegistered("myErrorScript"))
 {
 Page.ClientScript.RegisterStartupScript(this.GetType(),"myErrorScript", Msgscript);  

}


这篇关于如何在消息框中显示错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆