使用c#在asp.net中发送警报消息 [英] Alert msg in asp.net using c#

查看:113
本文介绍了使用c#在asp.net中发送警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Response.Write(< script language = javascript> alert('gk_szEnter_Value_Error_Message');< / script>);



不是显示所需的错误msg..its throw error..pls help

Response.Write("<script language=javascript> alert('"gk_szEnter_Value_Error_Message"'); </script>");

its not displaying the required error msg..its throwing error..pls help

推荐答案

这是因为你的代码和字符串没有在代码中正确关闭(双引号)并且代码的格式和语法在那里被打破。将您的代码更改为此类代码,



That is because your code and strings are not properly closed (the double quotes) in your code and the format and syntax of the code is broken there. Change your code to be like this one,

Response.Write(@"<script> 
                      alert('" + gk_szEnter_Value_Error_Message + "'); 
                 </script>");





现在代码将执行,并将流下来的脚本。 gk_szEnter_Value_Error_Message现在将被视为代码中的变量,并将获得它当时的值。



编写字符串的一种好方法是使用 String.Format() [ ^ ]函数,以有效的方式创建字符串,以避免串联;这会导致很多麻烦,就像在这种情况下为你做的那样。





Now the code would execute, and would stream down the script. The gk_szEnter_Value_Error_Message will now be considered as a variable in your code and will be given the value it has at that moment.

A good way of writing strings is to use the String.Format()[^] function, to create the strings in an efficient way, for avoiding the concatenation; which causes a lot of trouble like it did for you in this scenario.

Response.Write(String.Format("<script>alert('{0}');</script>"),    
                              gk_szEnter_Value_Error_Message);





这将是避免连接问题的有效方法。



个人提示,请勿指定脚本的语言。浏览器知道它是 JavaScript ;除非你使用其他一些脚本语言。我从来没有写过,浏览器根本就没有抱怨。 :)



This would now be an efficient way of avoiding the concatenation problems.

A personal tip, do not specify the language of your script. Browsers know it is JavaScript; unless you're using some other scripting language. I never do write it, and Browser doesn't complain at all. :)


如果确实有效,即使它不是有效的HTML。 :-)

当然,它显示gk_szEnter_Value_Error_Message(双引号),而不是变量的值。如果你想到的话,那就太奇怪了。



也许你想念的是:

http://support.microsoft.com/kb/307860 [ ^ ],

https://msdn.microsoft.com/en-us/library/bda9bbfx%28v=vs.100%29.aspx [ ^ ],

http://weblogs.asp.net/ahmedmoosa/embedded-code-and-内联服务器标签 [ ^ ]。



-SA
If does work, even if it is not a valid HTML. :-)
But of course, it shows "gk_szEnter_Value_Error_Message" (which double quotation marks), not the value of the variable. If you expected that, it would be quite weird.

Maybe what you miss is this:
http://support.microsoft.com/kb/307860[^],
https://msdn.microsoft.com/en-us/library/bda9bbfx%28v=vs.100%29.aspx[^],
http://weblogs.asp.net/ahmedmoosa/embedded-code-and-inline-server-tags[^].

—SA


这篇关于使用c#在asp.net中发送警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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