hi , i have created a web user control by the name test.ascx , i source code is
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="test.ascx.cs" Inherits="test" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
the code behind of test.ascx is
public partial class test : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Button clicked";
}
}
i am using the control in say del.aspx , which has the following source code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="del.aspx.cs" Inherits="del" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
</form>
</body>
</html>
on the button click event i am calling the web user control dynamically, the code behind of del.aspx is
public partial class del : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Control c1;
c1 = LoadControl("~/test.ascx");
Panel1.Controls.Add(c1);
}
}
the above code is working fine for calling the control dynamically, but when i try to fire the event of the control , the control just vanishes. I need to keep the control after the button has been pressed and display the output .