Image control not working

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Image control not working

    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>

    --

    Regards,
    Venkatesh.Bhupathi


    Venkatesh.Bhupathi Guest

  2. Similar Questions and Discussions

    1. Resize Bitmap image in image control in flex3
      I am loading an image in image control initially. Then I am applying color transform to that image and want to load that bitmap image in flex3. That...
    2. 'Edit Image' not working with Intel mac
      We run a studio with various macintosh's. Our latest mac, a Quad has been set up by transferring user info from a G4. When control clicking an image...
    3. IO Error when working with large image PDF files
      I have a 1Mb PDF file that contains a scanned image of an E size (36"x46") drawing. If I try to print this on B size (11"X17") paper there is no...
    4. Open Image in 'Kodak Image Edit Control' with web browser.
      hi, 1.I want to show a image file of type '.tif' in the browser window; for that I'm writting as ASP code page. 2.This '.tif' type image can be...
    5. Including WebForm Image Control in a Webform Table Control
      What is the code for including an image control in a Table control of a WebForm ???? regards
  3. #2

    Default Re: Image control not working

    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.

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU



    "Venkatesh.Bhupathi" <Venkatesh.Bhupathi @discussions.microsoft.com> wrote
    in message news:A9827EC9-EC77-4A06-8805-9DFE93E312D1@microsoft.com...
    >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>
    >
    > --
    >
    > Regards,
    > Venkatesh.Bhupathi
    >
    >

    Teemu Keiski Guest

  4. #3

    Default Image control not working

    Hi,

    I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of Dynamically loading image in Image control in ASP.NET and it helped me a lot. I had found another nice post over the internet which also have a wonderful explanation on Dynamically loading image in Image control in ASP.NET

    Thank you very much for your precious post.
    Ashish Pandey Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139