473,480 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Create event handler for componenent that's created programaticall

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
6 2237
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
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
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
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
2848
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
3
1783
by: leon | last post by:
hello friends, i am writing a page aspx and creating controls dinamicaly and then i must to create for each control the events as well. Anybody to know how????? happy day lion
3
23172
by: CodeRazor | last post by:
Hi, I am trying to dynamically create linkbuttons. They need an event handler, so i can respond to the user's click. I try to add the eventhandler on the fly, but when i click on the link, the...
3
2959
by: RSB | last post by:
Hi Every one Having tuff time creating web controls Dynamically. All i am trying to do is read a table and generate a list of ASP TEXT Box. So how do i create this Control dynamically and where...
3
2851
by: mg | last post by:
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...
13
2048
by: Richard W | last post by:
I have a very simple web page (ASP.NET) that I am trying to build. On the web page is a checkbox that enables or disables other controls based upon the checked status. However, .NET fails to...
15
26485
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
0
6903
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6726
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5318
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4468
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.