LanceZhang’s Blog

Dear friends, Welcome to my blog.

Make postback from ModalPopupExtender

To make a button which inside ModalPopup do a server-side onclick event, we should make sure the OkControlID of the ModalPopup is not the button we want to do a postback:

<%@ Page Language=”C#” %>
<%@ Register Assembly=”AjaxControlToolkit” Namespace=”AjaxControlToolkit” TagPrefix=”cc1″ %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”&gt;

<script runat=“server”>
protected void btn_OK_Click(object sender, EventArgs e)
Page.Title = “lance”;


<html xmlns=;>
<head runat=“server”>
<form id=“form1” runat=“server”>
<asp:LinkButton ID=“lnkbtn_comments” runat=“server”>LinkButton</asp:LinkButton>
<cc1:ToolkitScriptManager ID=“ToolkitScriptManager1” runat=“server”>
<asp:Panel ID=“panel_Comment” runat=“server” Width=“300px” Height=“150px” CssClass=“modalPopup”>
<br />
<br />
<td align=“left”>
<asp:TextBox ID=“txt_Title” runat=“server” />
<asp:TextBox ID=“txt_Comment” runat=“server” TextMode=“MultiLine” />
<asp:Button ID=“btn_OK” runat=“server” Text=“Save” OnClick=“btn_OK_Click” />
<td align=“left”>
<asp:Button ID=“btn_Cancel” runat=“server” Text=“Cancel” />
<cc1:ModalPopupExtender ID=“panel_Comment_ModalPopupExtender” runat=“server” TargetControlID=“lnkbtn_comments”
PopupControlID=“panel_Comment” DropShadow=“true” BackgroundCssClass=“modalBackground”


October 31, 2008 - Posted by | ASP.NET AJAX |

1 Comment »

  1. The ModalPopupExtender control:

    Notice anything in here?

    The OkControlID is not specified. Yep… that’s the entire solution. To bypass the functionality of the Extender and use the object’s own event model, simply do not link the objects. I’m sure the same works for the CancelControlID as well.

    Comment by Rory | March 1, 2011 | Reply

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: