473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Call a function from a dynamically created ImageButton

Is it possible to call a function from a ImageButton wich I create
at runtime?

That would be really interesting

Many thanks for any suggest.

Greetings Patrick Marti

Jul 21 '05 #1
1 1706
Hi Patrick

I would do it like this:

// this is created at runtime... maybe in onLoad or by another function....
Button someButton = new Button();
someButton.Name = "OnlyCallFunctionOne";
someButton.Click += new EventHandler( DynamicButton_Click );

Button someOtherButton = new Button();
someOtherButton.Name = "OnlyCallFunctionTwo";
someOtherButton.Click += new EventHandler( DynamicButton_Click );

// then you have the Click function
private void DynamicButton_Click( object sender, EventArgs e )
{
Button btn = (Button)sender;
switch( btn.Name )
{
case "OnlyCallFunctionOne": this.FunctionOne(); break;
case "OnlyCallFunctionTwo": this. FunctionTwo(); break;
}
}

private void FunctionOne()
{
// Some code...
}

private void FunctionTwo()
{
// Some code...
}
I just noticed you said ImageButton..... it should work just the same.

Hope it helps... did it in C# since u did not specify any other
language....then again i only use c# (^_^)

"Patrick Marti" <Pa**********@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
Is it possible to call a function from a ImageButton wich I create
at runtime?

That would be really interesting

Many thanks for any suggest.

Greetings Patrick Marti

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Mitchell | last post by:
I have some code behind that generates 10 imagebutton controls.... I can not seem to figure out how to trap the onclick event for each image and determine which image was clicked. Can someone...
4
by: John | last post by:
Hi all, This really is quite an urgent matter. I have a page with multiple, dynamically-loaded user controls and when a user clicks on a button, the whole form is submitted. Now at this stage...
2
by: Danny Bloodworth | last post by:
I have a usercontrol (login.ascx) that is very simple. It accepts input through two textboxes, and then the user clicks an Imagebutton to submit. I have a parent form that checks the page...
2
by: Jose Suero | last post by:
Hi all I have a dynamically created button, I can add an event handler with: AddHandler button.click, AddressOf static_function This works great, but what I need is to create a function that...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
3
by: tony collier | last post by:
Help please. I have a list of items on my page, alongside each of which i have a DELETE imagebutton. There can be from 0 to 6 items in the list and they are placed in a table which cannot be...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
2
by: Bruce | last post by:
I have a button on a form that creates multiple ImageButtons; I want each ImageButton's click event to then redirect to another URL. From doing some research, I understand this has to do with...
1
by: Patrick Marti | last post by:
Is it possible to call a function from a ImageButton wich I create at runtime? That would be really interesting Many thanks for any suggest. Greetings Patrick Marti
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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,...

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.