V
Venkatesh.Bhupathi
I have a user control inside a aspx page and i have event handler inside the
user control for the ImageClick EVent. But when i am trying to instantiate
the event in the .aspx page load event it is throwing object reference set to
null. Please find the sample code attached i have done please check the same
and let me know what mistake i am doing.
Code snippets
container.aspx
----------------
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute;
TOP: 8px" cellSpacing="1"
cellPadding="1" width="300" border="1">
<TR>
<TD></TD>
<TD></TD>
<TD>
<uc1:testCtrl id="TestCtrl1" runat="server"></uc1:testCtrl></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
</form>
Container.aspx.cs
-----
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace hollywoodclicks.members
{
/// <summary>
/// Summary description for Container.
/// </summary>
public class Container : System.Web.UI.Page
{
public testCtrl objCtrl;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
public void objCtrl_SearchTitle(object sender, ImageClickEventArgs e)
{
Response.Write("Responded to the ADD CLick");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
(ImageClickEventHandler)objCtrl.SearchTitle+=new
ImageClickEventHandler(objCtrl_SearchTitle);
//objCtrl.SearchTitle+=new ImageClickEventHandler(SearchTitle);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
testCtrl.ascx
--------------
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="testCtrl.ascx.cs" Inherits="test.members.testCtrl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD><INPUT id="Text1" type="text" name="Text1" runat="server"></TD>
<TD></TD>
</TR>
<TR>
<TD>
<asp:ImageButton id="ImageButton1" runat="server"
ImageUrl="../images/add.gif"></asp:ImageButton></TD>
<TD></TD>
</TR>
</TABLE>
user control for the ImageClick EVent. But when i am trying to instantiate
the event in the .aspx page load event it is throwing object reference set to
null. Please find the sample code attached i have done please check the same
and let me know what mistake i am doing.
Code snippets
container.aspx
----------------
<form id="Form1" method="post" runat="server">
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute;
TOP: 8px" cellSpacing="1"
cellPadding="1" width="300" border="1">
<TR>
<TD></TD>
<TD></TD>
<TD>
<uc1:testCtrl id="TestCtrl1" runat="server"></uc1:testCtrl></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
</form>
Container.aspx.cs
-----
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace hollywoodclicks.members
{
/// <summary>
/// Summary description for Container.
/// </summary>
public class Container : System.Web.UI.Page
{
public testCtrl objCtrl;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
public void objCtrl_SearchTitle(object sender, ImageClickEventArgs e)
{
Response.Write("Responded to the ADD CLick");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
(ImageClickEventHandler)objCtrl.SearchTitle+=new
ImageClickEventHandler(objCtrl_SearchTitle);
//objCtrl.SearchTitle+=new ImageClickEventHandler(SearchTitle);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
testCtrl.ascx
--------------
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="testCtrl.ascx.cs" Inherits="test.members.testCtrl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<TABLE id="Table1" cellSpacing="1" cellPadding="1" width="300" border="1">
<TR>
<TD><INPUT id="Text1" type="text" name="Text1" runat="server"></TD>
<TD></TD>
</TR>
<TR>
<TD>
<asp:ImageButton id="ImageButton1" runat="server"
ImageUrl="../images/add.gif"></asp:ImageButton></TD>
<TD></TD>
</TR>
</TABLE>