Jquery alertbox message is automatically disabled

I wrote the code in ascx script:

<script src="JScripts/jquery.alerts-1.1/jquery.alerts.js" type="text/javascript"></script> <script> $(function() { $('#ImageButton1').click(function() { jAlert('Please enter a valid Suggestion ID.', 'Case Entry'); }); }); </script> 

and the code behind:

 Page.ClientScript.RegisterStartupScript(this.GetType(), "Window", "callAlert();", true); 

the problem in the warning field is automatically turned off after a while, when the page is fully loaded

What is the reason that the warning window turns off after clicking the OK button and how to call the callAlert function correctly.

+4
source share
5 answers

If you use the main page or pages, you will not get the button's client ID, because you are declaring that it should be declared as $('#<%=ImageButton1.ClientID%>') or $('[id$=ImageButton1]') hoping she will solve your problem.

 $(document).ready(function(){ $('#<%=ImageButton1.ClientID%>').click(function() { alert('Please enter a valid Suggestion ID.', 'Case Entry'); }); }); 
0
source

You can try to put the next line before the function

 $(document).ready(function() { 

This will do:

 $(document).ready(function() { $('#ImageButton1').click(function() { jAlert('Please enter a valid Suggestion ID.', 'Case Entry'); }); }); }); 

If you wait until the page is ready, the warning field will not be overwritten (hopefully x)).

Also, when you check this text box, check if the condition is false, and then give a warning.
Is the condition not false? Create a check to check if the condition is true. If so? Redirection.

EDIT:

 var answer = Confirm: ("This page will now redirect. Are you ready?") if (answer) //redirect else return 
0
source

OK, so first it’s important to understand that $(function(){... and $(document).ready(function() {... equivalent, and nothing inside will be executed until the page is fully loaded In other words, there is no need to use

 Page.ClientScript.RegisterStartupScript(this.GetType(), "Window", "callAlert();", true); 

This can be removed. In addition, I see that you are probably using web forms. Remember that the Id attribute that will be displayed is not equal to the control attribute identifier. In other words, if you have a runat="server" control with ImageButton1 , using the syntax $('#ImageButton1') in your jQuery will not work.

Given this, I added the example below, which uses selectors based on class attributes.

 <script type="text/javascript"> $(function () { $('.ImageButton1').click(function (e) { var text = $('.TextBox1').val(); var redirect = true; if (!text) { redirect = confirm('Empty...are you sure?'); } if (redirect) { window.location.href = 'http://your-redirect-here.com'; } }); }); </script> <input class="TextBox1" type="text" /> <input class="ImageButton1" type="button" value="Click" /> 

This should lead you where you want to go. Let me know if you have any questions.

0
source
 var answer = Confirm: ("This page will now redirect. Are you ready?") if (answer) { //redirect } else { return false; } 
0
source

Put this after jAlert Box:

 return false; 

And call the function as follows:

 return callAlert(); 
0
source

All Articles