Search This Blog

Friday, February 21, 2014

Confirmation box from code behind (server side) c# using modalpopup ajax control

Confirmation box from code behind c# using modalpopup ajax control

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

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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 id="Head1" runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .modalBackground
        {
            background-color: Gray;
            filter: alpha(opacity=70);
            opacity: 0.7;
        }
       
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
    </asp:ScriptManager>
    <div>
        <asp:HiddenField ID="HiddenField1" runat="server" Value="2" />       
        <asp:Button ID="Button4" runat="server" Text="Validate and Open POPUP" OnClick="Button4_Click" /><br />
        <cc1:ModalPopupExtender id="ModalPopupExtender1" runat="server" targetcontrolid="Button1"
            popupcontrolid="PnlModal" backgroundcssclass="modalBackground">        </cc1:ModalPopupExtender>
        <asp:Button ID="Button1" runat="server" Text="Button" Style="visibility: hidden" />
        <asp:Panel ID="PnlModal" runat="server" Width="450px" style="display:none;                                                                    background-color: #ffffdd;
border-width: 3px;
border-style: solid;
border-color: Gray;
padding: 3px;
height:75px;
text-align:center; ">
            Are you sure want to Process?<br />
            <asp:Button ID="Button2" runat="server" Text="Yes" OnClick="Button2_Click" />
            <asp:Button ID="Button3" runat="server" Text="No" OnClick="Button3_Click" />
        </asp:Panel>
    </div>
    </form>
</body>
</html>


Code Behind:
using System;

public partial class ConfirmPopUp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        if (HiddenField1.Value == "2")
        {
            ModalPopupExtender1.Show();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {      
        //Your Processing code placed here       
        ModalPopupExtender1.Hide();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        ModalPopupExtender1.Hide();
    }
}

How To: Stop the ModalPopup Flicker
In above code PnlModal having the style="display:none;” to avoid flickering of confirmation box when page load happens
<asp:Panel ID="PnlModal" runat="server" Width="450px" style="display:none;”                                                                   

How To: Avoid “Object Required” javascript error from ScriptResource.axd when popup is shown
Don’t use PnlModal.Visible = false/true; from code behind to hide/show the popup, this is not required why because ModalPopupExtender will take care this behaviour.


Post a Comment

Popular Posts