close ajaxmodal popup only if validation passes

I have a ajaxmodal popup , where user enters text in the textbox. When user clicks ok , I want to execute server side code and only if validation passes, I want to close he modal popup. please help how can I achieve this?
TrialUserAsked:
Who is Participating?
 
BardobraveConnect With a Mentor Commented:
Well... you made an ajax call to your server code when the button is clicked on the modal window and close the window depending on the result returned from server code.
0
 
TrialUserAuthor Commented:
How do I do : "and close the window depending on the result returned from server code. " is my question
0
 
SriVaddadiConnect With a Mentor Commented:
Here is my understanding

1. You show the modal popup
2. Execute client side validation when user clicks ok on the popup
3. If validation is successful you execute the server side code

Solution

Hide the popup from java script if the client side validation fails.  $find('mpePromo').hide();
Hide the popup from server code if the client side validation is successful. this.mpePromo.Hide();
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
TrialUserAuthor Commented:
Ok, my question is how NOT to hide the popup when the validation fails on server side.
0
 
RobOwner (Aidellio)Commented:
what are you using for the ajax?  jquery for example has a return event when data is received back (onSuccess).  Your server side script should send a flag back indicating whether or not the validation has been successful.  If it has hide() the dialog, otherwise do something else....

Can you post your existing code around the dialog box and ajax call so that I can show you what I mean
0
 
TrialUserAuthor Commented:
<asp:modalpopupextender ID="mpePromo" runat="server"
        TargetControlID="lbtnPromo" PopupControlID="pnlPromo"
        OkControlID="imgClosePopup" BackgroundCssClass="modalBackGround"
        DropShadow="true"></asp:modalpopupextender>
    <asp:Panel ID="pnlPromo" runat="server" CssClass="pnlmodalbgLegend" DefaultButton="ibtOkPromo">
       
            <div style="float:right; margin-top:-20px; margin-bottom:0px; margin-left:20px; margin-right:-30px; cursor:pointer;">  
                <asp:Image ID="imgClosePopup" runat="server" AlternateText="Close [ X ]" ImageUrl="/Assets/Images/ProductDetails/CloseModalPopup.png" OnClientClick="$find('ModalPopupExtender1').hide(); return false;"/>
            </div>
            <div style="margin-top:5px; margin-left:12px;">
            <table cellpadding="5" cellspacing="5">
                <tr>
                 <td>
                     <asp:Image ID="imgLogoPopUpProduct" runat="server" ImageUrl="~/Assets/Images/ProductDetails/paperclipslogopopup.jpg" />
                 </td>
                </tr>
                <tr id="trMsg" runat="server" visible="false">
                <td>
                    <asp:Label ID="lblMsg" runat="server" ForeColor="Red" Font-Size="14px" Font-Bold="true" style="margin-left:10px;"></asp:Label>
                </td>
                </tr>
                </table>
            </div>
            <div style="border-top:1px solid #CACACA;margin-top:15px;padding:10px;border-bottom:1px solid #CACACA;margin-left:auto;margin-right:auto;width:85%;">  
            <table width="100%" cellpadding="5" cellspacing="5">
                <tr>
                    <td align="right">
                        <asp:Label ID="lblPromoCode" runat="server" Text="Promo Code:" Font-Bold="True" Font-Size="17px" ForeColor="#333333"></asp:Label>
                    </td>
                    <td align="right">
                        <asp:TextBox ID="txtPromotionCode" runat="server" CssClass="TextBox" Height="20px" Width="200px" MaxLength = "50"></asp:TextBox>
                    </td>
                </tr>
            </table>        
        </div>
        <div style="text-align: right;margin:20px;">
            <asp:ImageButton ID="ibtOkPromo" runat="server" ImageUrl = "/assets/images/ShoppingCart/OK_off.jpg" />
            <asp:ImageButton ID="ibtCancelPromo" runat="server" ImageUrl = "/assets/images/ShoppingCart/Cancel_off.jpg" />
        </div>                                          
    </asp:Panel>  
0
 
RobOwner (Aidellio)Commented:
Thanks for posting the code, however where is the javascript for the ajax call?
0
 
CodeCruiserCommented:
>OkControlID="imgClosePopup"
What happens if you remove that? Then in button click, run your server side code and then close the popup from server side

The technique would be similar to this

http://forums.asp.net/p/1016160/1366212.aspx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.