2

I have 2 buttons on the pop-up window (Ok and Cancel). I want to disable the "Cancel" button and only need OK button on pop-up. I had used the session time out on the page that needs only ok button to pop-up.

 <script src="jquery/js/jquery-1.8.3.js" type="text/javascript"></script>   

<script type="text/javascript">

var sess_pollInterval = 60000;
var sess_expirationMinutes = 3;
var sess_warningMinutes = 1;
var sess_intervalID;
var sess_lastActivity;

function initSession()
{    
    sess_lastActivity = new Date();
    sessSetInterval();

    $(document).bind('keypress.session', function (ed, e) {


        sessKeyPressed(ed, e);
    });
}

function sessSetInterval() 
{
    sess_intervalID = setInterval('sessInterval()', sess_pollInterval);
}

function sessClearInterval() 
{
    clearInterval(sess_intervalID);
}

function sessKeyPressed(ed, e) 
{
    sess_lastActivity = new Date();
}

function sessLogOut() 
{
    window.location.href = 'Logout.aspx';
}

function sessInterval()
{
    var now = new Date();
    //get milliseconds of differneces 
    var diff = now - sess_lastActivity;
    //get minutes between differences
    var diffMins = (diff / 1000 / 60);

    if (diffMins >= sess_warningMinutes)
    {
        //wran before expiring
        //stop the timer
        sessClearInterval();
        //promt for attention
   var active = confirm('Your session will expire in ' + (sess_expirationMinutes - sess_warningMinutes) +
            ' minutes (as of ' + now.toTimeString() + '), press OK to remain logged in ' +
                        'or press Cancel to log off. \nIf you are logged off any changes will be lost.');

        if (active == true)
        {
            now = new Date();
            diff = now - sess_lastActivity;
            diffMins = (diff / 1000 / 60);

            if (diffMins > sess_expirationMinutes)
            {
                sessLogOut();
            }
            else
            {
                initSession();
                sessSetInterval();
                sess_lastActivity = new Date();
            }
        }
        else
        {
            sessLogOut();
        }
    }
}
</script>

I tried this also :

$(".ui-dialog-buttonpane button:contains('Cancel')").attr("disabled", true).addClass("ui-state-disabled");

HTML code:

 <body onload="initSession()" >

<form id="form1" runat="server">
<div>

</div>
</form>
 </body>

1 Answers1

1

It's not possible to disbale a button on a standard confirm dialog, you need to use a custom layout for that.

Simplest might be using JqueryUI with the disable button option:

 $('<div></div>').dialog({
      title: "Your session will expire in " + 10 + " minutes ... TODO ",
      modal: true,
      buttons: [
          {
              id: 'confirm-ok',
              text: 'OK',
              click: function() {
                  alert("OK clicked");
              }
          }, {
               id: 'confirm-cancel',
               text: 'Cancel',
               click: function() {
                   alert("Cancel clicked");
              }
          }]
    });


if (true) { // <-- some custom logic
    $("#confirm-cancel").button("disable");
}

Here's a dummy sample

ılǝ
  • 3,440
  • 2
  • 33
  • 47
  • Its not working because i am calling function into . @ılǝ –  May 28 '15 at 08:11
  • you need to adapt your code, I'm only demonstrating how to provide a disabled confirm button – ılǝ May 28 '15 at 08:14
  • i did but still same happening..Above is my code, update your answer.@ ılǝ –  May 28 '15 at 08:19
  • Sorry, but as for the part of disabling a confirm button - the snippet is working, see again the fiddle. It shows a dialog with a disabled "cancel" button. If your code is not working - that may be due to other errors on your logic and implementation, which are not directly related to the original question. Please see [the question guideline](http://stackoverflow.com/help/how-to-ask) – ılǝ May 28 '15 at 08:32
  • @mazhar124 don't use onload, use: `$(initSession);` - or, more likely, move your js includes into the `` – freedomn-m May 28 '15 at 09:04