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