Prevent hiding of ModalPopupExtender when ok or cancel is clicked

I am using a asp.net ModalPopupExtender on a page, and would like to prevent the dialog from hiding when the user presses the ok button in certain conditions. But I can't seem to find a way.

What I am looking for is something like this

ajax:ModalPopupExtender ... OnOkScript="return confirm('You sure?')" ...

if confirm is false, then the modal dialog doesn't disappear.

Answers


From my understanding in your specific situation you would not wire up the button, and just wire up a script to handle the conditional, then you can close it via JS.


The following JavaScript function will allow you to achieve this:

function conditionalHide(clientID)
{
    if (confirm('You sure?'))
    {
        $find(clientID).hide();
    }
}

You can wire this up to your asp:Button control in the Page_Load event of your page

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        btnOK.OnClientClick = string.Format("conditionalHide('{0}'); return false;",
            panPopup_ModalPopupExtender.ClientID);
    }
}

Some notes:

  • panPopup_ModalPopupExtender is your ModalPopupExtender
  • The return false; prevents a postback from occurring when the user clicks the button
  • You could hard-code the ClientID of the ModalPopupExtender, but this introduces an (additional) maintainance headache. The approach shown is the best one that I've found to alleviate this overhead

Need Your Help

Ruby script error

ruby osx terminal

I've got a ruby script

Cache Implemented Using an Array - ArrayIndexOutOfBoundsException (Java)

java arrays caching indexoutofboundsexception

I simulate a web cache replacement algorithm. I have N objects of type Request available for caching and L requests for those objects that arrive to the cache in a serial fashion.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.