You can use ajax. Before confirmation box of javascript you can check the user session status by ajax. If the session is unavailable then you can redirect by javascript.
var J = jQuery.noConflict();
function IsLoginChecked() {
return true;
J.ajax({
url: "Checker.aspx",
type: "GET",
dataType: 'html',
data: {},
success: function (data) {
if(data=="false")
window.location.href = "Login.aspx";
else
{
return confirm('Are you sure to confirm?');
}
return false;
},
error: function () {
return false;
}
});
}
Checker.aspx code
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
if(Session["User"] == null)
return false;
else
return true;
Response.End();
}
add OnClientClick="return IsLoginChecked()==true?true:false;" to the button property.