Create event handler for componenent that's created programaticall

Discussion in 'ASP .Net' started by =?Utf-8?B?bWc=?=, Nov 12, 2004.

  1. The code below creates an ImageButton when a LinkButton is clicked.

    How can I create an event handler for this ImageButton which can't be seen
    in the Design pane?


    private void LinkButton1_Click(object sender, System.EventArgs e)
    {
    System.Web.UI.WebControls.ImageButton ImageButton1 = new ImageButton();
    ImageButton1.Height = 18;
    ImageButton1.Width = 100;
    ImageButton1.ImageUrl = @"\images\continue.gif";
    Panel1.Controls.Add(ImageButton1);
    }
     
    =?Utf-8?B?bWc=?=, Nov 12, 2004
    #1
    1. Advertising

  2. C# should be like this:

    this.ImageButton1.Click += new System.EventHandler(this.ImageButton1_Click);

    "mg" wrote:

    >
    > The code below creates an ImageButton when a LinkButton is clicked.
    >
    > How can I create an event handler for this ImageButton which can't be seen
    > in the Design pane?
    >
    >
    > private void LinkButton1_Click(object sender, System.EventArgs e)
    > {
    > System.Web.UI.WebControls.ImageButton ImageButton1 = new ImageButton();
    > ImageButton1.Height = 18;
    > ImageButton1.Width = 100;
    > ImageButton1.ImageUrl = @"\images\continue.gif";
    > Panel1.Controls.Add(ImageButton1);
    > }
     
    =?Utf-8?B?VGFtcGEgLk5FVCBLb2Rlcg==?=, Nov 12, 2004
    #2
    1. Advertising

  3. this.ImageButton1.Click += new System.EventHandler(this.ImageButton1_Click);

    resulted in the following error message:

    'Page' does not contain a definition for 'ImageButton1'

    I then rewrote the line as follows:

    ImageButton1.Click += new System.EventHandler(ImageButton1_Click);

    This code resulted in the following error message:

    ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    does not match delegate 'void System.EventHandler(object, System.EventArgs)'

    ???




    "Tampa .NET Koder" wrote:

    > C# should be like this:
    >
    > this.ImageButton1.Click += new System.EventHandler(this.ImageButton1_Click);
    >
    > "mg" wrote:
    >
    > >
    > > The code below creates an ImageButton when a LinkButton is clicked.
    > >
    > > How can I create an event handler for this ImageButton which can't be seen
    > > in the Design pane?
    > >
    > >
    > > private void LinkButton1_Click(object sender, System.EventArgs e)
    > > {
    > > System.Web.UI.WebControls.ImageButton ImageButton1 = new ImageButton();
    > > ImageButton1.Height = 18;
    > > ImageButton1.Width = 100;
    > > ImageButton1.ImageUrl = @"\images\continue.gif";
    > > Panel1.Controls.Add(ImageButton1);
    > > }
     
    =?Utf-8?B?bWc=?=, Nov 12, 2004
    #3
  4. The code below runs without error but the Alert does not appear. Can you
    tell me how to make the Alert popup when I click the ImageButton?

    private void LinkButton1_Click(object sender, System.EventArgs e)
    {
    System.Web.UI.WebControls.ImageButton ImageButton1 = new ImageButton();
    ImageButton1.Height = 18;
    ImageButton1.Width = 100;
    ImageButton1.ImageUrl = @"\images\continue.gif";
    Panel1.Controls.Add(ImageButton1);
    ImageButton1.Click += new ImageClickEventHandler(ImageButton1_Click);
    }

    private void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
    Response.Write("<script language='javascript'>alert('TEST');</script>");
    }

    "mg" wrote:

    >
    > The code below creates an ImageButton when a LinkButton is clicked.
    >
    > How can I create an event handler for this ImageButton which can't be seen
    > in the Design pane?
    >
    >
    > private void LinkButton1_Click(object sender, System.EventArgs e)
    > {
    > System.Web.UI.WebControls.ImageButton ImageButton1 = new ImageButton();
    > ImageButton1.Height = 18;
    > ImageButton1.Width = 100;
    > ImageButton1.ImageUrl = @"\images\continue.gif";
    > Panel1.Controls.Add(ImageButton1);
    > }
     
    =?Utf-8?B?bWc=?=, Nov 13, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5kcmV3IFdpZWQ=?=

    Adding event handler for dynamically created controls

    =?Utf-8?B?QW5kcmV3IFdpZWQ=?=, Apr 19, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,413
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Apr 25, 2004
  2. UT-BadBoy
    Replies:
    0
    Views:
    421
    UT-BadBoy
    Apr 17, 2006
  3. Replies:
    1
    Views:
    733
    Damien
    Feb 22, 2007
  4. gnewsgroup
    Replies:
    4
    Views:
    692
    gnewsgroup
    Feb 19, 2008
  5. Adi
    Replies:
    2
    Views:
    198
Loading...

Share This Page