Post to another page from several submit buttons

K

Kees de Winter

Hi,

On a form I have several submit-buttons, each of which should post its own
set of variables (e.g. price and name of a product) to another page, e.g. an
orderpage. There can only be one form, so what can I do now? I know I can do
it using a Javascript function that sets the variables in the form, but
isn't there any way without Javascript? Or can one rely on the user having
Javascript.

Using asp.net 2.0 VB.Net.
Thanks very much for any help.
 
L

Lisa Ashley Rafter

Hi Kees,
One way to do it is to make them all aspbuttons.
Put this on the form:
<asp:button id=myButton runat="server" Font-Size="8pt" Height="20px"
Width="64px" CausesValidation="False" Text="Copy"></asp:button>
Put this in your codebehind:
Private Sub myButton_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles myButton.Click
......
build your new URL here
myURL = "mypage.aspx" & ....
.....
response.redirect (myURL , true)
End Sub

Handle the click on the codebehind page, then build your URL you'll to
post with there.
There are other way's to do it......but this is one easy way.
Response.Redirect() sometimes isn't the best way though.
Hope that helps,
Lisa
 
E

Eliyahu Goldin

First of all, you can absolutely rely on user having javascript. Otherwise
your program won't be usable anyway. Nothing useful is possible in asp.net
without javascript.

Secondly, you can use the PreviousPage property on the second page to access
the property of the first page directly. This may save you from javascript.
 
D

Damien

Eliyahu said:
First of all, you can absolutely rely on user having javascript. Otherwise
your program won't be usable anyway. Nothing useful is possible in asp.net
without javascript.

I beg to differ. Plenty of useful applications have and will be written
in asp.net without using any javascript whatsoever. In our place, we
use javascript, but only to enhance the experience, not for core
functionality.

There was a whole thread discussing this back in September, started by
Mark Rae and titled "Javascript or not javascript". As an update from
my comments back then, now that we've been running our newest site for
3 months now, we're finding the javascript disabled crowd is currently
accounting for 27% of our traffic.

Damien
 
E

Eliyahu Goldin

Damien,

In what sense do you call an application with bad user experience useful?

I still remember the time when developers where forced to program for MS-DOS
since not everyone had/wanted Windows. And in MS-DOS one could always
achieve the same functionality.
 
B

bruce barker

there is no supported way in asp.net. their solution also uses
javascript. you can fall back to standard html which does support
multiple forms and postback urls.

-- bruce (sqlwork.com)
 
D

Damien

Eliyahu said:
Damien,

In what sense do you call an application with bad user experience useful?

I still remember the time when developers where forced to program for MS-DOS
since not everyone had/wanted Windows. And in MS-DOS one could always
achieve the same functionality.

--
Well, lets see.

For a long running process, if the user has javascript, they get a
stable page which uses ajax to check for progress and updates the page
apropriately. No javascript, they get a page that does a refresh every
five seconds - it looks jerky, but it works.

For a text box where the user has to provide the name of a company - we
have a drop-down list which pulls in possible names (based on what the
user has typed) from a list of ~200 most likely names to be typing. If
they don't have javascript, they don't get the list, but they can still
type in the company names (and anyone is allowed to enter a name not on
the list anyway)

For validation - if the client has javascript, they get client side
validation which saves round trips to the server if they've got errors
on the page. No javascript, they have to wait until they submit the
form to get the same kind of feedback.

So, if the user has *chosen* to disable javascript (and you'd hope
they'd be aware that doing so limits their user experience
possibilities), we still allow them to use our system.

Now, how do the penalties for developing like this work out? Well, you
have to have server side validation anyway, to protect yourself from
malicious people. The text box with the "predictive" text just renders
as a text box anyway - no development effort whatsoever for the
non-javascript approach. And the progress page? There are about twelve
additional lines of code to support the non-ajax functionality.

Damien
 
E

Eliyahu Goldin

This is nice of you to cater for disable javascripting, but I doubt the
benefits of that override the limitations and the development penalties that
are too many to start counting.
 
E

Edwin Knoppert

You can fool asp.net by clearing out a view important objects using js like
viewstate and a few others.

Some partial code i grabbed from my site:

<script language="javascript">
function download()
{
var x = document.forms[0];
var sOldAction = x.action;
var sOldTarget = x.target;
var oVS = document.getElementById('__VIEWSTATE');
var sOldViewstate = oVS.value;
oVS.value = "";
x.action = "http://yoururlhere.aspx";
x.target = "_blank";
document.forms[0].submit();
x.target = sOldTarget;
x.action = sOldAction;
oVS.value = sOldViewstate;
}
</script>
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top