Board index » Web Programming » finding which button is pressed

finding which button is pressed

Web Programming15
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


-
 

Re:finding which button is pressed

Earliest solution i can suggest is to query Request.Form("Button")



Best Regards

Jignesh Desai

www.dotnetjini.com



"Jonathan Crawford" <jc@jcrawford.co.uk>wrote in message

Quote
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



















-

Re:finding which button is pressed

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

"Jignesh Desai" <jignesh_desai@hotmail.com>wrote in message

Quote
Earliest solution i can suggest is to query Request.Form("Button")



Best Regards

Jignesh Desai

www.dotnetjini.com



"Jonathan Crawford" <jc@jcrawford.co.uk>wrote in message

news:%23BV6yrMIGHA.2300@TK2MSFTNGP15.phx.gbl...

>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

>

>

>

>

>

>

>









-

Re:finding which button is pressed

ASP.NET 1.1 and aspbuttons are server control buttons



thanks jc



--



"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com>wrote in

message news:%23kq3zQPIGHA.1124@TK2MSFTNGP10.phx.gbl...

Quote
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

"Jignesh Desai" <jignesh_desai@hotmail.com>wrote in message

news:umH1v6MIGHA.2212@TK2MSFTNGP15.phx.gbl...

>Earliest solution i can suggest is to query Request.Form("Button")

>

>Best Regards

>Jignesh Desai

>www.dotnetjini.com

>

>"Jonathan Crawford" <jc@jcrawford.co.uk>wrote in message

>news:%23BV6yrMIGHA.2300@TK2MSFTNGP15.phx.gbl...

>>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

>>

>>

>>

>>

>>

>>

>>

>

>









-

Re:finding which button is pressed

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

"Jonathan Crawford" <jc@jcrawford.co.uk>wrote in message

Quote
ASP.NET 1.1 and aspbuttons are server control buttons



thanks jc



--



"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com>wrote

in message news:%23kq3zQPIGHA.1124@TK2MSFTNGP10.phx.gbl...

>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

>"Jignesh Desai" <jignesh_desai@hotmail.com>wrote in message

>news:umH1v6MIGHA.2212@TK2MSFTNGP15.phx.gbl...

>>Earliest solution i can suggest is to query Request.Form("Button")

>>

>>Best Regards

>>Jignesh Desai

>>www.dotnetjini.com

>>

>>"Jonathan Crawford" <jc@jcrawford.co.uk>wrote in message

>>news:%23BV6yrMIGHA.2300@TK2MSFTNGP15.phx.gbl...

>>>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

>>>

>>>

>>>

>>>

>>>

>>>

>>>

>>

>>

>

>









-

Re:finding which button is pressed

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



-