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” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;

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

</script>

<html xmlns=http://www.w3.org/1999/xhtml&#8221;>
<head runat=“server”>
<title></title>
</head>
<body>
<form id=“form1” runat=“server”>
<div>
<asp:LinkButton ID=“lnkbtn_comments” runat=“server”>LinkButton</asp:LinkButton>
<cc1:ToolkitScriptManager ID=“ToolkitScriptManager1” runat=“server”>
</cc1:ToolkitScriptManager>
<asp:Panel ID=“panel_Comment” runat=“server” Width=“300px” Height=“150px” CssClass=“modalPopup”>
<br />
<br />
<center>
<table>
<tr>
<td>
Title:
</td>
<td align=“left”>
<asp:TextBox ID=“txt_Title” runat=“server” />
</td>
</tr>
<tr>
<td>
Comment:
</td>
<td>
<asp:TextBox ID=“txt_Comment” runat=“server” TextMode=“MultiLine” />
</td>
</tr>
<tr>
<td>
<asp:Button ID=“btn_OK” runat=“server” Text=“Save” OnClick=“btn_OK_Click” />
</td>
<td align=“left”>
<asp:Button ID=“btn_Cancel” runat=“server” Text=“Cancel” />
</td>
</tr>
</table>
</center>
</asp:Panel>
<cc1:ModalPopupExtender ID=“panel_Comment_ModalPopupExtender” runat=“server” TargetControlID=“lnkbtn_comments”
PopupControlID=“panel_Comment” DropShadow=“true” BackgroundCssClass=“modalBackground”
CancelControlID=“btn_Cancel”>
</cc1:ModalPopupExtender>
</div>
</form>
</body>
</html>

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:

WordPress.com Logo

You are commenting using your WordPress.com 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: