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.
source share