Surya sasidhar
Surya sasidhar

Reputation: 30313

Asp .net Modal popup control cancelbutton ? Cancel Contol?

in web applicaiton,[asp.net] i am using modal popu control, it is working fine, but in modal popup close button [cancel button] event, i write a code for redirecting to another page but it is not reirecting [may be event is not firing], can you help me.

<asp:Panel ID ="slideshow1" runat ="server" >
    <asp:GridView ID ="grd" runat ="server" ></asp:GridView>
    <asp:Button ID ="btnClos" runat ="server" onclick="btnClos_Click" Text ="X close" />
</asp:Panel>

<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID ="btn"
    CancelControlID="btnClos"  PopupControlID="slideshow1" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Button ID ="btn" runat ="server" style="display:none;" />

Upvotes: 0

Views: 4736

Answers (1)

VinayC
VinayC

Reputation: 49195

I suspect that perhaps ModalPopupExtender is not propagating the submit of close button as it's cancel button for the extender. There are couple of alternatives:

Instead of using it as CancelControlID argument, You can use java-script API for the ModalPopupExtender to hide it. For example,

<asp:Panel ID ="slideshow1" runat ="server" >
    <asp:GridView ID ="grd" runat ="server" ></asp:GridView>
    <asp:Button ID ="btnClos" runat ="server" onClick="btnClos_Click" OnClientClick="return DoClose();" Text ="X close" />
</asp:Panel>

<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID ="btn"
    PopupControlID="slideshow1" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>

<script type="text/javascript">

 function DoClose() {
    // close the modal popup
    $('<%= ModalPopupExtender1.ClientID %>').hide();

    // return true so that submit will happen
    return true;
 }

</script>

As you want to redirect to another page, the better alternative will be to simply redirect to different page rather than using server side redirect.

<asp:Panel ID ="slideshow1" runat ="server" >
    <asp:GridView ID ="grd" runat ="server" ></asp:GridView>
    <asp:Button ID ="btnClos" runat ="server" OnClientClick="return DoClose();" Text ="X close" />
</asp:Panel>

<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID ="btn"
    CancelControlID="btnClos"  PopupControlID="slideshow1" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>

    <script type="text/javascript">

     function DoClose() {
        // redirect
        window.location.href = '/ToAnotherPage.aspx?q=some';

        // return false so that submit will be blocked
        return false;
     }

    </script>

Upvotes: 1

Related Questions