0

I click submit button before test time is completed So I show a confirm message "Do you want to really Quit this test" and I click the submit button when Time is completed (Time left is 00:00:00) through javascript, but then also it asks user with confirm message Which I do not want to show on completion of time, How can I achieve this? This is my button

<asp:Button ID="btnSubmit"  class="btn" runat="server"
                                    OnClientClick="return confirm('Do you  want to really Quit this test');" Text="Submit Test"
                                    OnClick="btnSubmit_Click" />

This is javascript through which I call Click event when test time is over

<script type="text/javascript">
         function 
    display() {

                var hours = document.getElementById('<%=HidH.ClientID %>');
                var minutes = document.getElementById('<%=HidM.ClientID %>');
                var seconds = document.getElementById('<%=HidS.ClientID %>');

                if (hours.value == 0 && minutes.value == 0 && seconds.value == 0) {
                    alert("Time Given For this Test is Over");
                    document.getElementById('btnSubmit').click();
                 }
                } 
   </script>
1
  • 1
    I recommend using a dedicated "postback" control separate from the aforementioned UI button. Then it's trivial to handle the appropriate callback on the server and there is no need to muck with anything else. Commented Nov 14, 2013 at 5:58

1 Answer 1

1

Instead of binding click event inline call a function where you will prompt user for confirmation and make it option depending on timeout.

Change

OnClientClick="return confirm('Do you  want to really Quit this test');" 

To

OnClientClick="return myConfirmFun()" 

Define myConfirmFun as under.

var showConfirm = false; // defind gloablly

function myConfirmFun()
{
    if(showConfirm) 
    {
        showConfirmm = false; 
        confirm('Do you  want to really Quit this test');
    }
}

In the display function

if (hours.value == 0 && minutes.value == 0 && seconds.value == 0) {
    showConfirm = false;
    alert("Time Given For this Test is Over");
}
else
    showConfirm = true;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.