HI All,
I have created one web user control for (Change Password.ascx ) and one .aspx page (Home.aspx) and then add the web-user control to a page using Drag and Drop. and it is working fine.
Now I want to add the user control dynamically to a page. like
Control ctrl=LoadControl("ChangePass.ascx");
PlaceHolder1.Controls.Add(ctrl);
I am able to add the control to the Home.aspx But the button placed inside Web User Control not firing its click event.
Click event of the button is not fired If I not add the user control dynamically.
I google this thing but not getting proper reply.
Please help me to solve this issue.
Thanks
Here is my code for User Control (ChangePass.ascx")
=====================================
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ChangePass.ascx.cs" Inherits="ChangePass" %>
<table class="style1">
<tr>
<td>
New Password
</td>
<td>
<asp:TextBox ID="txtNewPassword" runat="server" Width="218px" TextMode="Password"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtNewPassword"
ErrorMessage="Enter New Password"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
Confirm Password
</td>
<td>
<asp:TextBox ID="txtCNewPassword" runat="server" Width="218px" TextMode="Password"></asp:TextBox>
</td>
<td>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txtNewPassword"
ControlToValidate="txtCNewPassword" Display="Dynamic" ErrorMessage="Password and Confirm Password does not match"></asp:CompareValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtCNewPassword"
Display="Dynamic" ErrorMessage="Enter Confirm Password"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#990000"></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" />
</td>
</tr>
</table>
==============================================
Code for Web User Control .cs File (ChangePass.ascx.cs)
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class ChangePass : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
Class1 objCls = new Class1();
int i;
i = objCls.UpdateEmployeePassword(Convert.ToInt32(Session["EmpId"].ToString()), txtNewPassword.Text);
if (i > 0)
{
Label1.Text = "Password Change Successfully";
}
else
{
}
}
}
}
n Home page I palce a Button and on Button Click I Load the Wen User Control
on Click Event of Button:-
Control ctrl=LoadControl("ChangePass.ascx");
PlaceHolder1.Controls.Add(ctrl);
================================================
It load the control but click event for changing the password is not File.
Please help to solve this.
Thanks