locked
ModalPopupExtender OnOkScript keep popup open RRS feed

  • Question

  • User347587616 posted

    I would like keep open my popup after user press ok button.

    when user click on okbutton I validate data inserted on modalpopup and I want keep open the popup in case some inserted data aren't correctly, but after click on okbutton, popup automaticly get closed...

     how can avoid it?

    Thursday, September 14, 2006 10:31 AM

All replies

  • User-396192383 posted

    The approach I took was:

     

    1. Turned off defaultsubmitbehavior and manually added the postback to be performed in the page.

    2. Added a boolean to determine if in ModalMode (ie: set to true and once x number of scenarios - in your case validation) set it back to false.

    3. On the OnLoad event or Page_Load I do a check - and if you are using the latest toolkit release off codeplex - there is now a modal property to toggle the visibility instead of having to add the scripting manually.  If the modal mode boolean is true then I force the modal back open if page is a pastback ...

    4. Implement IPostBack event and data handlers and set code to trap the ok button postback you configured.

    5. You may also find that you need to also do the LoadControlState() and SaveControlState if you have any dynamic controls...

     

     

    Thursday, September 14, 2006 2:03 PM
  • User347587616 posted

    thanks for suggestion... but my sistuation is easier... I guess..

    I want just avoid that OnOkScript close my popup... i validate data client side... I mean I don't manage any postback...

    my problem is at the OnOkScript function... my popup is closed in any case

    Thursday, September 14, 2006 2:21 PM
  • User220125910 posted
    Hi crixo,

    Here's a suggestion that might work for you.  Create a new button called "fakeOK" that has the text "OK," and set your old OK button's style to have display: none.  Now you can do whatever you want in fakeOK's onclick (including calling oldOK.click(); to force OnOKScript to run and close the popup).

    Thanks,
    Ted
    Monday, September 18, 2006 9:50 PM
  • User-396192383 posted

    Here's even a easier idea:

     

    Don't bother with IPostback handlers...

     

    Instead capture the _EventArgument at the OnInit phase and immediately reroute it (Or move it elsewhere if you need it)...as a string...

     

    string PBArgument = HttpContext.Current.Request.Params["__EVENTARGUMENT"];

    if  (PBArgument ="blah"))

    { ... do this}

    That is at least how I cirvumvent certain issues with dynamic controls with atlas related features...

    Then at least you do not have to deal with gludgy UI elements.... 

    Monday, September 18, 2006 9:56 PM
  • User258853998 posted

    I was struggling with the same issue - I wanted to keep the modal form open if the user failed the data entry validations I had setup.  I noticed that the ModalPopupExtender.cs had a public Show() method, so in my event handler of my 'Save' button on the popup, I raised a 'SaveFailed' (if the validation criteria was not met) event to the main form and in that event handler I simply called myPopup.Show(); and it all worked - the form remained open and the form fields even retained the values previously entered by the user.

    Tuesday, July 10, 2007 1:10 PM
  • User-521190856 posted

    This guy here has the best option

    http://tiredblogger.wordpress.com/2007/02/27/modalpopupextender-button-or-anything-events/

    Just dont include the property OkControlID and DONE

    Wednesday, September 2, 2009 5:00 PM
  • User1731989136 posted

    TRY THIS BELOW CODE :) . Hope for help

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPopUpSolution.aspx.cs" Inherits="TestPopUpSolution" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <style runat="server" type="text/css">
            .modalPopup {
                background-color:#ffffdd;
                border-width:0px;
                border-style:solid;
                border-color:Gray;
                padding:0px;
            }

            .modalBackground {
                background-color:Gray;
                filter:alpha(opacity=70);
                opacity:0.7;
            }
        </style>
    </head>
    <body>

        <form id="form1" runat="server">
        <div>
         <asp:Button ID="ButSave" runat="server" Text="Button" OnClientClick="return ConfirmData();"/>
         <br />
         <asp:ScriptManager ID="ScriptManager" runat="server">
         </asp:ScriptManager>
         <br />
       
        <script type="text/javascript">
            function ConfirmData()
            {
                if(PageValidateFunction())
                {
                    $get('<%=HiddenField.ClientID%>').value="true";
                    return true;             
                }
                else
                {
                    var modalPopupBehavior = $find('<%=ModalPopUp.ClientID%>');
                    
                    if(document.getElementById('<%=HiddenField.ClientID %>').value=="false")
                    {                       
                        modalPopupBehavior.show();
                        return false;
                    }
                    else
                         return true;
                }
            }
            
            function PageValidateFunction()
            {
                //Write YOUR LOGIC VALID here
                return false;
            }
            
            function onOk() {            
                document.getElementById('<%=ButSave.ClientID%>').click();
                return true;
            }
        </script>
        
        <asp:Panel ID="pnlID" runat="server" Style="display:none" CssClass="modalPopup">
            <table id="tblID" cellspacing="0" cellpadding="4" border="1" rules="all" style="color: rgb(51, 51, 51); border-collapse: collapse;">
                <tr style="color: White; background-color: rgb(93, 123, 157); font-weight: bold;">
                    <th scope="col">Company</th>
                    <th scope="col">ISIN</th>
                    <th scope="col">DirectorName</th>
                    <th scope="col">DirectorPosition</th>
                    <th scope="col">TransactionDate</th>
                    <th scope="col">Nr of shares</th>
                    <th scope="col">Price per share</th>
                    <th scope="col">Total of share</th>
                    <th scope="col">Holding Percent</th>
                </tr>
                
                <tr style="color: rgb(51, 51, 51); background-color: rgb(247, 246, 243);" >
                    <td><asp:Label ID="lbCompanyConfirm" runat="server"></asp:Label></td>
                    <td><asp:Label ID="lbISINConfirm" runat="server"></asp:Label></td>
                    <td><asp:Label ID="lbDirectorConfirm" runat="server"></asp:Label></td>
                    <td><asp:Label ID="lbDirectorPositionConfirm" runat="server"></asp:Label></td>
                    <td><asp:Label ID="lbTrandateConfirm" runat="server"></asp:Label></td>                
                    <td><asp:Label ID="lbNrShareConfirm" runat="server"></asp:Label></td>  
                    <td><asp:Label ID="lbPricepersharesConfirm" runat="server"></asp:Label></td>
                    <td><asp:Label ID="lbTotalShare" runat="server"></asp:Label></td>                
                    <td><asp:Label ID="lbHoldingPerConfirm" runat="server"></asp:Label></td>
                </tr>  
                
                <tr align="center">
                    <td ><asp:Button runat="server" ID="btnOK" Text="Approve"/></td>
                    <td colspan="7"></td>
                    <td ><asp:Button runat="server" ID="btnCancel" Text="Cancel"/></td>
                </tr>  
            </table>
        </asp:Panel>
        
       
         <asp:ModalPopupExtender
             ID="ModalPopUp"
             runat="server"
             DropShadow="true"
             PopupControlID="pnlID"
             OkControlID="btnOK"
             OnOkScript="onOk()"
             CancelControlID="btnCancel"
             BackgroundCssClass="modalBackground"
             TargetControlID="btnHidden"         
             >    
        </asp:ModalPopupExtender>   
        
        <asp:HiddenField ID="HiddenField" runat="server" Value="false"/>
        <asp:Button ID="btnHidden" runat="server" Text="Show" style="display:none"/>
        </div>
        </form>
    </body>
    </html>

    Wednesday, September 2, 2009 10:18 PM