Board index » Web Programming » finding which button is pressed
|
Brisk
|
|
Brisk
|
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 - |
| Jignesh
Registered User |
Tue Jan 24 04:04:40 CST 2006
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 QuoteHi - |
| S
Registered User |
Tue Jan 24 08:41:09 CST 2006
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 QuoteEarliest solution i can suggest is to query Request.Form("Button") - |
| Jonathan
Registered User |
Tue Jan 24 09:17:22 CST 2006
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... QuoteJC, - |
| S
Registered User |
Tue Jan 24 10:25:30 CST 2006
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 QuoteASP.NET 1.1 and aspbuttons are server control buttons - |
| slagomite
Registered User |
Tue Jan 24 10:44:22 CST 2006
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 - |
