By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

Create event handler for componenent that's created programaticall

P: n/a
mg

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 Design?
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);
}
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi,

Use ImageButtton1.[EventName] += new EventHandler ([eventhandler])

Regards,
Peter Jausovec
(http://blog.jausovec.net)

"mg" <mg@discussions.microsoft.com> je napisal v sporočilo
news:C6**********************************@microsof t.com ...

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 Design?
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);
}

Nov 16 '05 #2

P: n/a
Do you want to hook up an existing method or create a new one at runtime?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

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 Design?
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);
}

Nov 16 '05 #3

P: n/a
mg
At this point, I'm not sure.

I'd very much appreciate your providing the code for both cases, including
the code for the eventhandler itself.

I'm still confused about how this all works.

"Richard Blewett [DevelopMentor]" wrote:
Do you want to hook up an existing method or create a new one at runtime?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

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 Design?
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);
}

Nov 16 '05 #4

P: n/a
mg

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)'

???
"Peter Jausovec" wrote:
Hi,

Use ImageButtton1.[EventName] += new EventHandler ([eventhandler])

Regards,
Peter Jausovec
(http://blog.jausovec.net)

"mg" <mg@discussions.microsoft.com> je napisal v sporoèilo
news:C6**********************************@microsof t.com ...

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 Design?
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);
}


Nov 16 '05 #5

P: n/a

Sorry, I pasted wrong code. Here is the correct one:
ImageButton btn = new ImageButton ();
btn.Click += new ImageClickEventHandler(btn_Click);

and the handler:

private void btn_Click(object sender, ImageClickEventArgs e)


Regards,
Peter Jausovec
(http://blog.jausovec.net)

mg" <mg@discussions.microsoft.com> je napisal v sporočilo
news:E9**********************************@microsof t.com ...

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)'

???
"Peter Jausovec" wrote:
Hi,

Use ImageButtton1.[EventName] += new EventHandler ([eventhandler])

Regards,
Peter Jausovec
(http://blog.jausovec.net)

"mg" <mg@discussions.microsoft.com> je napisal v sporoeilo
news:C6**********************************@microsof t.com ...
>
> 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 Design?
>
>
> 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);
> }
>
>


Nov 16 '05 #6

P: n/a
mg
The following code ran without error, but the alert did not appear. Can you
see the problem?

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>");
}

"Peter Jausovec" wrote:

Sorry, I pasted wrong code. Here is the correct one:
ImageButton btn = new ImageButton ();
btn.Click += new ImageClickEventHandler(btn_Click);

and the handler:

private void btn_Click(object sender, ImageClickEventArgs e)


Regards,
Peter Jausovec
(http://blog.jausovec.net)

mg" <mg@discussions.microsoft.com> je napisal v sporoèilo
news:E9**********************************@microsof t.com ...

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)'

???
"Peter Jausovec" wrote:
Hi,

Use ImageButtton1.[EventName] += new EventHandler ([eventhandler])

Regards,
Peter Jausovec
(http://blog.jausovec.net)

"mg" <mg@discussions.microsoft.com> je napisal v sporoeilo
news:C6**********************************@microsof t.com ...
>
> 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 Design?
>
>
> 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);
> }
>
>


Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.