473,404 Members | 2,179 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,404 software developers and data experts.

parameters with events

Hi everybody,

I've got a Button on a webform and I want an onClick event.
So normally this will be something like :
/// protected void onClickEvent(Object sender, EventArgs e)

But I want to pass an extra parameter when I click on the button.
How Can I do that?

In javascript, it's easy to create your own onclick functions because you
don't need the sender en eventargs objects.

thanks

Filip
Nov 16 '05 #1
3 1703
By LinkButton you can set two properties:

string LinkButton.CommandName
string LinkButton.CommandArgument

protected void onClickEvent(Object sender, EventArgs e)

{
LinkButton linkButton=(LinkButton)sender;
if (linkButton.CommandName=="...." && linkButton.CommandArgument=="...")
....
}

"Filip De Backer" <fi*************@hotmail.com.(donotspam)> schrieb im
Newsbeitrag news:01**********************************@microsof t.com...
Hi everybody,

I've got a Button on a webform and I want an onClick event.
So normally this will be something like :
/// protected void onClickEvent(Object sender, EventArgs e)

But I want to pass an extra parameter when I click on the button.
How Can I do that?

In javascript, it's easy to create your own onclick functions because you
don't need the sender en eventargs objects.

thanks

Filip

Nov 16 '05 #2
Hi,

Do not use OnClick, use OnCommand and use CommandArgument to set the
parameter that you need.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Filip De Backer" <fi*************@hotmail.com.(donotspam)> wrote in message
news:01**********************************@microsof t.com...
Hi everybody,

I've got a Button on a webform and I want an onClick event.
So normally this will be something like :
/// protected void onClickEvent(Object sender, EventArgs e)

But I want to pass an extra parameter when I click on the button.
How Can I do that?

In javascript, it's easy to create your own onclick functions because you
don't need the sender en eventargs objects.

thanks

Filip

Nov 16 '05 #3
Hi,

I use this approach a lot with a list control, in this way you can set the
argument using databinding and you don ;t have to take care in the code
behind searching for the control that fired the event.

You use onclick when you don;t need extra info for the event, otherwise I
would use oncommand.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"tbain" <tb***@discussions.microsoft.com> wrote in message
news:75**********************************@microsof t.com...
Great idea as long as the argument is static or the button property
"CommandArgument" can be changed dynamically as needed. There's always many ways to implement something. He could also create his own button type by
inheritance and write his own event and eventargs. Probably depends on his
programming style, possible re-use, and what the parameter actually is for. Besides OnCommand being a bit "cleaner" is there a reason to not use OnClick?
Peace!
:)Thom

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Do not use OnClick, use OnCommand and use CommandArgument to set the
parameter that you need.
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"Filip De Backer" <fi*************@hotmail.com.(donotspam)> wrote in message news:01**********************************@microsof t.com...
Hi everybody,

I've got a Button on a webform and I want an onClick event.
So normally this will be something like :
/// protected void onClickEvent(Object sender, EventArgs e)

But I want to pass an extra parameter when I click on the button.
How Can I do that?

In javascript, it's easy to create your own onclick functions because you don't need the sender en eventargs objects.

thanks

Filip


Nov 16 '05 #4

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

Similar topics

8
by: Mark Flippin | last post by:
This is for a reporting problem using: Access 2000 SQL Server 2000 Both at SP3 I've a stored procedure in SQL Server 2000 which builds a result set from a disparate set of tables, utilizing...
4
by: news.microsoft.com | last post by:
In one of my books called "Mastering C#" there is a statement that reads "All event handler delegates must return void and accept two parameters. The first parameter is an object, and it represents...
33
by: C# Learner | last post by:
Note ---- Please use a fixed-width font to view this, such as Courier New. Problem
3
by: Colin Basterfield | last post by:
Hi, In Delphi all the events that 'it' generates, e.g. a button click, there is a default parameter Sender of type TObject, so whenever I defined my own I always did that too, so now converting...
8
by: Sam Kuehn | last post by:
How do I accomplish the fallowing (is it even possible). Say I write a UserControl "MyControl.ascx". Now I use LoadControl("MyControl.ascx"). But I really want MyControl to require parameters in...
5
by: Martin Bischoff | last post by:
Hi, is it possible to modify the values of a SqlDataSource's select parameters in the code behind before the select command is executed? Example: I have an SqlDataSource with a...
6
by: Jack | last post by:
I have the following: * An OLEDBCommand with command text "SELECT CAMPAIGN, DAY_OUT WHERE (CAMPAIGN LIKE '@campaign')" * A DataAdapter that point the select to the above command * A data grid...
18
by: **Developer** | last post by:
I always define events with the parameters ByVal sender As Object, ByVal e As EventArgs Even if they are not used. Seems I read someplace that's the thing to do. So I then do:
7
by: Andrus | last post by:
I noticed that DataGridView CellValidated() and other event handler first parameter is object: Grid.CellValidated+=new DataGridViewCellEventHandler(Grid_CellValidated); .... void...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.