Image control not working

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>
 
T

Teemu Keiski

Member name in code-behind of the Page, should match to the ID of the
control.

If your user control is:

<uc1:testCtrl id="TestCtrl1" runat="server"></uc1:testCtrl>

it's code-behind member should be

public testCtrl TestCtrl1;

I don't see the coee-behind class for the UC itself, but hopefully you have
the custom event (SearchTitle) declared there and so forth.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top