简体   繁体   中英

asp.net response.write with bootbox.alert

Response.Write("alert(Username or password invalid);");

from codebehind to warn user. But i wanna show it more goodlooking. I saw bootbox and added to library

<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootbox.min.js"></script>

But when i enter wrong info it doesnt make any alert. Can you tell me where i am making this wrong please. Thank You

This code i am using; (in button click, after it goes 'else')

  else
   {
 Response.Write("<script type=text/javascript>bootbox.alert(Username or password invalid);</script>");
   }

You're not quoting the string in JavaScript. Take a look at what you're emitting to the page:

Response.Write("<script type=text/javascript>bootbox.alert(Username or password invalid);</script>");

This will result in:

<script type=text/javascript>bootbox.alert(Username or password invalid);</script>

The browser will probably correct the unquoted type attribute for you, but JavaScript won't correct the unquoted string for you. Your JavaScript console is probably showing an error that Username isn't defined or something of that nature.

So first you'll need to properly quote the strings:

Response.Write("<script type=\"text/javascript\">bootbox.alert('Username or password invalid');</script>");

Now, even aside from that, you really shouldn't use Response.Write() to emit values to the page. It gives you no control over where on the page things are placed, and that can be important. Take a look at RegisterStartupScript as an alternative. This would include the client-side code in a more appropriate location in the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM