Search This Blog

Thursday, January 15, 2015

calling ModalPopupExtender from server side (code behind) in C# & using RequiredFieldValidator in ModalPopupExtender of AjaxControlToolkit

How to use RequiredFieldValidator in ModalPopupExtender (Ajax control tool kit):

by default validators are not work in ModalPopupExtender without using
ValidationGroup check the below example for more information

How to use ModalPopupExtender from code behind (server side code) in C# :


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<
asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel ID="UpdatePanelNavigation" UpdateMode="Always" runat="server"><ContentTemplate>
<asp:Button ID="btnUpdate" runat="server" Text="Edit Details" Width="150px" OnClick="btnUpdate_Click" Visible="true" />
<asp:HiddenField ID="hdnForModelDetails" runat="server" />
<cc1:ModalPopupExtender ID="mpeDetails" runat="server"TargetControlID="hdnForModelDetails" PopupControlID="pnlUpdateDetails"BackgroundCssClass="modalBackground" DropShadow="false"CancelControlID="btnIFSCCancel" />
<asp:Panel ID="pnlUpdateDetails" DefaultButton="btnIFSCOk" runat="server" CssClass="modalPopup"><table><tr><td style="padding-left: 15px; text-align: left; vertical-align: top">IFSC Code:</td><td><asp:TextBox ID="txtIfscCode" runat="server" MaxLength="34"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="txtIfscCode" runat="server" ErrorMessage="Please enter IFSC code" Display="Dynamic" ValidationGroup="IFSCValidationGroup"></asp:RequiredFieldValidator></td></tr></table><br />
<div style="text-align: center"><asp:Button ID="btnIFSCOk" Text="OK" Width="80px" runat="server" OnClick="btnIFSCOk_Click" ValidationGroup="IFSCValidationGroup" /><asp:Button ID="btnIFSCCancel" Text="Cancel" Width="80px" runat="server" OnClick="btnIFSCCancel_Click" /></div>
</asp:Panel></ContentTemplate></asp:UpdatePanel>
Code:

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

protected void btnUpdate_Click(object sender, EventArgs e){
mpeDetails.Show();
}

protected void btnIFSCCancel_Click(object sender, EventArgs e){
}

protected void btnIFSCOk_Click(object sender, EventArgs e){
}
}
Post a Comment

Popular Posts