Hi, everybody !
Please see the following code and error and please give me the solution. i have included all the needed file. this thing works fine in one old aspx page.
namespace WebApplication1
{
///
/// Summary description for WebForm9.
///
public class WebForm9 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.LinkButton lkbtnCommonChat;
protected System.Web.UI.HtmlControls.HtmlForm form;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
form=(HtmlForm)this.FindControl("WebForm9");
Button button = new Button();
form.Controls.Add(button); //it shows error here button.ID = "Community";
button.Text="Community";
button.Style["Alignment"]= "left";
button.BackColor=System.Drawing.Color.Transparent;
button.BorderStyle=System.Web.UI.WebControls.BorderStyle.None;
button.ForeColor=System.Drawing.Color.Blue;
button.Style["POSITION"]="relative";
}
}
}
Error:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error: Line 27
Line 25: form=(HtmlForm)this.FindControl("WebForm9");
Line 26: Button button = new Button();
Line 27: form.Controls.Add(button); Line 28: button.ID = "Community";
Line 29: button.Text="Community";
Source File: c:\inetpub\wwwroot\webapplication1\webform9.aspx.cs Line: 27
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
WebApplication1.WebForm9.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication1\webform9.aspx.cs:27
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
|