modalpopupextender: button clicked but postback needs to be 'stopped'

540 Views Asked by At

I have an ASP.NET webforms application in which I want to show a popup only if a user is not logged in. The event that shows the popup is triggered by a button click, the code behind then shows the modal popup if the user is not logged on.

The problem is that the page gets refreshed (posted back), and only then the popup gets shown. What I want to achieve is that the popup show without the page being refreshed.

Any ideas?

Thanks,

Tom

1

There are 1 best solutions below

0
On

'I want the popup to show without the page being refreshed'

Here's how to make a submit button that only submits when a user is logged in, (by adding client-side validation). The button will either:
- provide a popup for a not-logged-in user and do nothing else
or
- submit/postback for a logged-in user.

  <form ...>
    ...
    <button type="submit" onclick="checkIfUserIsLoggedIn(event);">Submit</button>
    <script type="text/javascript">
    function checkIfUserIsLoggedIn(event) {
        if (userIsNotLoggedIn()) {  //userIsNotLoggedIn() is a js function you'll need to write
            alert("Please log in and re-submit.");
            event.preventDefault();  // prevent submission / postback
            event.stopPropogation(); // prevent submission / postback, probably unnecessary
        }
    }
    </script>
  </form>