Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2005, 01:52 PM
Authorized User
 
Join Date: Nov 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple submit buttons

The form has two buttons, if button "One" is presed, the variable gets "one", if button "Two" is pressed, the variable gets "two". Of course I may need to use something completely different.

All this is in a file called multibtn.asp.

Please enlighten me!

<BODY>
<%
Dim variable

'I'm pretty sure code goes here here for it to get
'information based on what button is pressed

If variable = "One" Then
    Response.Write "button 1 was clicked"
End If

If variable = "Two" Then
    Response.Write "button 2 was clicked"
End If
%>

<FORM ACTION="multibtn.asp" METHOD="post">
<INPUT TYPE="SUBMIT" VALUE="One" NAME="cmdOne">
<INPUT TYPE="SUBMIT" VALUE="Two" NAME="cmdTwo">
</FORM>

</BODY>
 
Old November 28th, 2005, 02:41 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

This is classic ASP, not ASP.NET right? In that case, you're better off posting in one of the classic ASP forums in the ASP and ASP.NET category, listed here: http://p2p.wrox.com/asp-net-asp-12

That said, what you're after is Request.Form(ButtonName)

Give both buttons the same name, like this:
Code:
<form action="multibtn.asp" method="post">
  <inut type="SUBMIT" value="One" name="SubmitButton">
  <inut type="SUBMIT" value="Two" name="SubmitButton">
</form>
And then you can use this:
Code:
Dim buttonPressed
buttonPressed = Request.Form("SubmitButton")

Select Case buttonPressed
  Case "One"
    Response.Write "button 1 was clicked"
  Case "Two"
    Response.Write "button 2 was clicked"
End Select
HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 28th, 2005, 04:55 PM
Authorized User
 
Join Date: Nov 2005
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This did exactly what I needed. Excellent, TYVM!

PS: Sorry about posting in the wrong forum (=
 
Old November 26th, 2007, 04:39 PM
Registered User
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Can you show this example using .net?

I just need it up to setting a variable to the id of the button that was clicked. And I am using multiple ImageButton..

Basically I have multiple ImageButtons calling the same function. And in that function I want to set a string variable with the ImageButton that was clicked ID.

string ImageButtonClicked = FormName.ButtonClicked.Name;
(above is logic I want to use with incorrect syntax)

Thanks!
Dan
 
Old November 27th, 2007, 05:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Dan,

Simple have each ImageButton call the same method, then cast the sender argument to a Control and retrieve its ID:

Markup
Code:
<asp:ImageButton ID="ImageButton1" runat="server" onclick="ImageButton1_Click" />
<asp:ImageButton ID="ImageButton2" runat="server" onclick="ImageButton1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
Code Behind
Code:
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
  WebControl myControl = sender as WebControl;
  if (myControl != null)
  {
    Label1.Text = myControl.ID;
  }
}
If you cast to an ImageButton instead of a more generic WebControl, you can access ImageButton specific properties as well.

Cheers and hope this helps,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old November 27th, 2007, 02:45 PM
Registered User
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Worked like a charm! Thank you much.:)

 
Old November 27th, 2007, 05:33 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004





Similar Threads
Thread Thread Starter Forum Replies Last Post
2 Submit Buttons ... HOW? Benno Dreamweaver (all versions) 1 November 23rd, 2004 12:14 PM
multiple Image submit buttons set default to last sam HTML Code Clinic 2 June 30th, 2004 02:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.