finding which button is pressed

J

Jonathan Crawford

Hi

I have a form with two butons

I know if the form is a postback but I can't
find anyway to tell which button was clicked,
on the form load event.

I have a feeling that this is obvious.

Any guidance appreciated

thanks

jc
 
S

S. Justin Gengo [MCP]

JC,

Are you using asp.net 1.1 or 2.0? And are these buttons regular html buttons
or buttons set with runat="server"?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

S. Justin Gengo [MCP]

Jonathan,

I just wanted to double check. In that case this will work:

'---Check if the sender is a button

If sender.GetType Is GetType(Button) Then

'---If it is a button check which one

Dim ButtonSent As Button = CType(sender, Button)

Dim ButtonName As String = ButtonSent.ID

End If


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

slagomite

You can always just compare the reference of "sender" with that of your
Button variables (assuming you have declared protected class-level
Button variables having the same names as the IDs of your Buttons):

[in C# - sorry, I'm not familiar enough with VB.NET to be 100% sure
about the code]

protected Button btnButton1;
protected Button btnButton2;
....
private void Button_ClickHandler(object sender, EventArgs e)
{
if(sender == this.btnButton1)
{
...
}
else if(sender == this.btnButton2)
{
...
}
}

(I believe in VB.NET, the conditional would be
If sender = Me.btnButton2 Then ...
)

Hope this helps...

Luke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,294
Latest member
LandonPigo

Latest Threads

Top