|
 |
aspx_beginners thread: How do I get button name or Text in it's onClick Event?
Message #1 by "Roberts, Ben" <Ben.Roberts@a...> on Wed, 13 Nov 2002 14:28:07 -0700
|
|
Hola all,
I have two buttons that are going to be using identical functions unless I
can get the name ot ID or even text from the button from Object sender or
System.EventArgs e.
Any help?
TIA
Message #2 by "Peter Zahos" <Peter@i...> on Thu, 14 Nov 2002 08:55:09 +0800
|
|
Tia,
Here's an excerpt that may assist you:
Using Command events rather than Click events affords the developer the
opportunity to pass additional information via the control's CommandName
and CommandArgument properties. The following example assigns the
command name "Sort" and the command argument "Asc" to a Button control
and toggles the command argument between "Asc" and "Desc" to perform
alternating ascending and descending sorts:
<asp:Button Text=3D"Sort" ID=3D"SortButton" OnCommand=3D"OnSort"
CommandName=3D"Sort" CommandArgument=3D"Asc" RunAt=3D"server" />
.
.
.
<script language=3D"C#" runat=3D"server">
void OnSort (Object sender, CommandEventArgs e)
{
if (e.CommandName =3D=3D "Sort" &&
e.CommandArgument.ToString () =3D=3D "Asc") {
// TODO: Perform ascending sort
SortButton.CommandArgument =3D "Desc";
}
else if (e.CommandName =3D=3D "Sort" &&
e.CommandArgument.ToString () =3D=3D "Desc") {
// TODO: Perform descending sort
SortButton.CommandArgument =3D "Asc";
}
}
</script>
Command events are useful for "overloading" button controls and having
them perform different actions based on the value of CommandArgument.
They can also be used to connect multiple buttons to a single handler
and have the handler respond differently depending on which button was
clicked.
Hope it helps
Pete
-----Original Message-----
From: Roberts, Ben [mailto:Ben.Roberts@a...]
Sent: Thursday, 14 November 2002 5:28 AM
To: aspx_beginners
Subject: [aspx_beginners] How do I get button name or Text in it's
onClick Event?
Hola all,
I have two buttons that are going to be using identical functions unless
I can get the name ot ID or even text from the button from Object sender
or System.EventArgs e.
Any help?
TIA
Message #3 by "Roberts, Ben" <Ben.Roberts@a...> on Thu, 14 Nov 2002 09:01:37 -0700
|
|
Thanks, that works like a champ!
-----Original Message-----
From: Peter Zahos [mailto:Peter@i...]
Sent: Wednesday, November 13, 2002 4:55 PM
To: aspx_beginners
Subject: [aspx_beginners] RE: How do I get button name or Text in it's
onClick Event?
Tia,
Here's an excerpt that may assist you:
Using Command events rather than Click events affords the developer the
opportunity to pass additional information via the control's CommandName
and CommandArgument properties. The following example assigns the
command name "Sort" and the command argument "Asc" to a Button control
and toggles the command argument between "Asc" and "Desc" to perform
alternating ascending and descending sorts:
<asp:Button Text="Sort" ID="SortButton" OnCommand="OnSort"
CommandName="Sort" CommandArgument="Asc" RunAt="server" />
.
.
.
<script language="C#" runat="server">
void OnSort (Object sender, CommandEventArgs e)
{
if (e.CommandName == "Sort" &&
e.CommandArgument.ToString () == "Asc") {
// TODO: Perform ascending sort
SortButton.CommandArgument = "Desc";
}
else if (e.CommandName == "Sort" &&
e.CommandArgument.ToString () == "Desc") {
// TODO: Perform descending sort
SortButton.CommandArgument = "Asc";
}
}
</script>
Command events are useful for "overloading" button controls and having
them perform different actions based on the value of CommandArgument.
They can also be used to connect multiple buttons to a single handler
and have the handler respond differently depending on which button was
clicked.
Hope it helps
Pete
-----Original Message-----
From: Roberts, Ben [mailto:Ben.Roberts@a...]
Sent: Thursday, 14 November 2002 5:28 AM
To: aspx_beginners
Subject: [aspx_beginners] How do I get button name or Text in it's
onClick Event?
Hola all,
I have two buttons that are going to be using identical functions unless
I can get the name ot ID or even text from the button from Object sender
or System.EventArgs e.
Any help?
TIA
|
|
 |