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" "">
<html xmlns="">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
            background-color: Gray;
            filter: alpha(opacity=70);
            opacity: 0.7;
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
        <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;
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" />

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")
    protected void Button2_Click(object sender, EventArgs e)
        //Your Processing code placed here       
    protected void Button3_Click(object sender, EventArgs e)

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