aspx_beginners thread: R: RE: How do I get button name or Text in it's
onClickEvent?
Hi,
I also think that using the Command event is the best way.
However I think that, if "sender" is the Oject parameter of the onClick
function, you can detect the ID of the button also in the following way:
CType(sender,Control).ID in VB
((Control)sender).ID in C#
Bye
Enzo
-----Messaggio originale-----
Da: Peter Zahos [mailto:Peter@i...]
Inviato: gioved=EC 14 novembre 2002 1.55
A: aspx_beginners
Oggetto: [aspx_beginners] RE: How do I get button name or Text in it's
onClickEvent?
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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
CONFIDENTIALITY NOTICE
This message and its attachments are addressed solely to the persons
above and may contain confidential information. If you have received
the message in error, be informed that any use of the content hereof
is prohibited. Please return it immediately to the sender and delete
the message. Should you have any questions, please contact us by
replying to MailAdmin@t... Thank you
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D