Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
I have a quiz exam in which form submission occurs after the specified time out with an alert message with OK button. Problem is that when time out occurs and after pressing OK button, time out alert is displaying again and again until the page redirected to result page.
I want it to show once and then the page to be get submitted.
Button2 is my submit button and mins is a variable for time in minutes.
Please help me !


C#
Literal1.Text = "<script>$(function(){ var note = $('#note'), ts = new Date(2012, 0, 1),newYear = true; if((new Date()) > ts){	ts = (new Date()).getTime() + " + mins + "*60*1000; newYear = false;	}	$('#countdown').countdown({	timestamp	: ts,callback	: function(days, hours, minutes, seconds){   var message = ''; var timer = ''; message += days + ' day' + ( days==1 ? '':'s' ) + ', '; message += hours + ' hour' + ( hours==1 ? '':'s' ) + ', '; message += minutes + ' minute' + ( minutes==1 ? '':'s' ) + ' and '; message += seconds + ' second' + ( seconds==1 ? '':'s' ) + ' <br />';	timer = hours + ':' + minutes + ':' + seconds;	note.html(timer); if (minutes.toString() == '0' && seconds.toString() == '0') {$('#note').attr('id', '#note1');	  alert('Time up');	   $('#Button2').click();    return;	}	} }); });</script>";


HTML Code
ASP.NET
<table>
     <tr>
        <td style="padding-left:15px;">Time Left :</td>
        <td>
        <p id="note" style="height: 24px; line-height: 38px;"></p>
        </td>
     </tr>
</table>
<script type="text/javascript">
//$('input:submit').click(function () {
//$('input:submit').attr("disabled", true);
//});
var clicked = false;
function DisableButton() {
   if (clicked == false) {
     clicked = true;
     //var btn = $("#Button2");
     //btn.value = "Processing";
     //$('#Button2').text("Processing");
     //alert("Submitted");
     return true;
   }
   else { 
     alert("Submitted");
     $("#note").attr("id", "#note1");
     //$('#Button2').text("Processing");
     return false;
    }
 }
</script>
<asp:Button ID="Button2" runat="server" CssClass="gbutton"  Text="Submit" OnClientClick="return DisableButton();" OnClick="Button2_Click" BorderStyle="Outset" />
Posted
Updated 1-Jan-15 0:02am
v4
Comments
ZurdoDev 1-Jan-15 11:07am    
So, you're saying that DisableButton() is called again and again?
arifk786k 10-Jan-15 3:53am    
Yes alert timeup showing untill the page is redirected to result page.
ZurdoDev 10-Jan-15 10:39am    
Yes, if alert is in page 1 it will show before you can redirect to page 2.
arifk786k 19-Jan-15 7:15am    
I want alert show only once, not again again

1 solution

Hi,

Use a hiddenfield there in your aspx page and set the flag value there in the hidden field for checking the chicked variable.

Here each time the value is getting replaced with the false and you are getting popup repeatedly.

Check for the ckicked variable value each time.

Thanks
Sisir Patro
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900