Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > How to post form variables to another URL using asp.net

Reply
Thread Tools

How to post form variables to another URL using asp.net

 
 
DOUGLAS HEESTAND
Guest
Posts: n/a
 
      02-24-2004
How do you post to another URL (i.e. an external non-asp.net page). I
am trying to create a payment solution with authorize.net and they
require that you post to a URL they provide. I want to use asp.net to
take advantage of the nice form validation and other things but I
can't get it to post to anything but itself. If I use
"Response.Redirect()" it doesn't post the form variables,
"Server.Transfer()" doesn't work because it's not a file on my web
server.

Am I forced to use a standard html form?

thanks!
 
Reply With Quote
 
 
 
 
Raterus
Guest
Posts: n/a
 
      02-24-2004
I'm sure you've tried setting the action attribute on the <form
runat="server"> to the page you want, which won't work, because as soon as
you put runat="server" asp.net is going to change the action to the page
it's on to allow for the postback. If you take away runat="server", none of
your server controls can be within this form. Hmmm...

How do you get around this?, javascript On the button you are clicking
to send the info to the other server do this.

myButton.Attributes.Add("onClick", "javascript:
document.forms[0].action='http://otherserver.com/theirpage.html';document.fo
rms[0].__VIEWSTATE=''")

You may want to clear out the viewstate hidden form field too, since the
other page won't be able to do much with it, and no sense making your client
send more than they need to.

Don't you submit the form yourself though, just change the action. Let
asp.nets __doPostBack() function handle the posting (this will ensure your
validators fire too). Asp.net never has to know you changed the
action..heehee.

I'm assuming this will work (maybe not the javascript since I just wrote
that by hand), though I've never actually tried this. Let me know how it
works!

--Michael

"DOUGLAS HEESTAND" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> How do you post to another URL (i.e. an external non-asp.net page). I
> am trying to create a payment solution with authorize.net and they
> require that you post to a URL they provide. I want to use asp.net to
> take advantage of the nice form validation and other things but I
> can't get it to post to anything but itself. If I use
> "Response.Redirect()" it doesn't post the form variables,
> "Server.Transfer()" doesn't work because it's not a file on my web
> server.
>
> Am I forced to use a standard html form?
>
> thanks!



 
Reply With Quote
 
 
 
 
DOUGLAS HEESTAND
Guest
Posts: n/a
 
      02-25-2004
It worked!! What a brilliant idea! I had to do some modifications
because it didn't work if I had form validation as well. (That places
a javascript call on the "onClick" event of the submit button too, so
I couldn't get the two to work in the proper sequence.) So instead, I
attached your idea to the onSubmit property of the form itself...

<script language="VB" runat="server">
Sub btnSubmit_Click(Sender As Object, E As EventArgs)
myform.Attributes.Add("onSubmit",
"javascript:document.forms[0].action='http://otherserver.com/theirpage.html';")
End Sub
</script>

Thanks so much!! Do you think this is a risky approach because some
browsers might not handle the javascript properly??

"Raterus" <raterus@localhost> wrote in message news:<uoFDMAy#(E-Mail Removed)>...
> I'm sure you've tried setting the action attribute on the <form
> runat="server"> to the page you want, which won't work, because as soon as
> you put runat="server" asp.net is going to change the action to the page
> it's on to allow for the postback. If you take away runat="server", none of
> your server controls can be within this form. Hmmm...
>
> How do you get around this?, javascript On the button you are clicking
> to send the info to the other server do this.
>
> myButton.Attributes.Add("onClick", "javascript:
> document.forms[0].action='http://otherserver.com/theirpage.html';document.fo
> rms[0].__VIEWSTATE=''")
>
> You may want to clear out the viewstate hidden form field too, since the
> other page won't be able to do much with it, and no sense making your client
> send more than they need to.
>
> Don't you submit the form yourself though, just change the action. Let
> asp.nets __doPostBack() function handle the posting (this will ensure your
> validators fire too). Asp.net never has to know you changed the
> action..heehee.
>
> I'm assuming this will work (maybe not the javascript since I just wrote
> that by hand), though I've never actually tried this. Let me know how it
> works!
>
> --Michael
>
> "DOUGLAS HEESTAND" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > How do you post to another URL (i.e. an external non-asp.net page). I
> > am trying to create a payment solution with authorize.net and they
> > require that you post to a URL they provide. I want to use asp.net to
> > take advantage of the nice form validation and other things but I
> > can't get it to post to anything but itself. If I use
> > "Response.Redirect()" it doesn't post the form variables,
> > "Server.Transfer()" doesn't work because it's not a file on my web
> > server.
> >
> > Am I forced to use a standard html form?
> >
> > thanks!

 
Reply With Quote
 
DOUGLAS HEESTAND
Guest
Posts: n/a
 
      02-25-2004
After more fiddling it seems I can't get it to co-exist with form
validation. Changing the value of the "onSubmit" property of the form
causes the last validation to be bypassed. If I try to change the
value of the "onClick" property of the submit button I get something
like this when it is rendered into HTML:

<input type="submit" name="btnSubmit" value="Submit"
onclick="javascript:document.forms[0].action='http://othersite.com/otherform.html;if
(typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); "
language="javascript" id="btnSubmit" />

So it submits before validating and I can't make it validate first. I
could create a custom javascript function but that is starting to get
hokey and just plain ugly. I'd rather use a vanilla html form at that
point!

I can't believe ASP.NET can't handle this situation!

-Doug
 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      02-25-2004
hi Douglas,

Below i am providing you with a quick copy and paste from the docs. For a
working example of how this can work for you, go to :
http://www.bluevisionsoftware.com/We...px?Name=PayPal


Requests and Responses in the .NET Framework
The .NET Framework uses specific classes to provide the three pieces of
information required to access Internet resources through a request/response
model: the Uri class, which contains the URI of the Internet resource you
are seeking; the WebRequest class, which contains a request for the
resource; and the WebResponse class, which provides a container for the
incoming response.

Client applications create WebRequest instances by passing the URI of the
network resource to the WebRequest.Create method. This static method creates
a WebRequest instance for a specific protocol, such as HTTP. The WebRequest
instance that is returned provides access to properties that control both
the request to the server and access to the data stream that is sent when
the request is made. The GetResponse method on the WebRequest instance sends
the request from the client application to the server identified in the URI.
In cases in which the response might be delayed, the request can be made
asynchronously using the BeginGetResponse method on the WebRequest instance,
and the response can be returned at a later time using the EndGetResponse
method.

The GetResponse and EndGetResponse methods return a WebResponse instance
that provides access to the data returned by the server. Because this data
is provided to the requesting application as a stream by the
GetResponseStream method, it can be used in an application anywhere data
streams are used.

The WebRequest and WebResponse classes are the basis of pluggable
protocols-an implementation of network services that enables you to develop
applications that use Internet resources without worrying about the specific
details of the protocol that each resource uses. Descendant classes of
WebRequest are registered with the WebRequest class to manage the details of
making the actual connections to Internet


As an example, the HttpWebRequest class manages the details of connecting to
an Internet resource using HTTP. By default, when the WebRequest.Create
method encounters a URI that begins with "http:" or "https:" (the protocol
identifiers for HTTP and secure HTTP), the WebRequest instance that is
returned can be used as is, or it can be typecast to HttpWebRequest to
access protocol-specific properties. In most cases, the WebRequest instance
provides all the necessary information for making a request.

Any protocol that can be represented as a request/response transaction can
be used in a WebRequest. You can derive protocol-specific classes from
WebRequest and WebResponse and then register them for use by the application
with the static WebRequest.RegisterPrefix method.

When client authorization for Internet requests is required, the Credentials
property of the WebRequest supplies the necessary credentials. These
credentials can be a simple name/password pair for basic HTTP or digest
authentication, or a name/password/domain set for NTLM or Kerberos
authentication. One set of credentials can be stored in a NetworkCredentials
instance, or multiple sets can be stored simultaneously in a CredentialCache
instance. The CredentialCache uses the URI of the request and the
authentication scheme that the server supports to determine which
credentials to send to the server.





"DOUGLAS HEESTAND" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> After more fiddling it seems I can't get it to co-exist with form
> validation. Changing the value of the "onSubmit" property of the form
> causes the last validation to be bypassed. If I try to change the
> value of the "onClick" property of the submit button I get something
> like this when it is rendered into HTML:
>
> <input type="submit" name="btnSubmit" value="Submit"
>

onclick="javascript:document.forms[0].action='http://othersite.com/otherform
..html;if
> (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); "
> language="javascript" id="btnSubmit" />
>
> So it submits before validating and I can't make it validate first. I
> could create a custom javascript function but that is starting to get
> hokey and just plain ugly. I'd rather use a vanilla html form at that
> point!
>
> I can't believe ASP.NET can't handle this situation!
>
> -Doug



 
Reply With Quote
 
Alessandro Zifiglio
Guest
Posts: n/a
 
      02-25-2004
and on a final note, if authorize.net is providing you with payment
solutions then they should have some code example as to how you can connect
and what you need to do. Try contacting them if this information is not
available to you on their faqs page etc.

"Alessandro Zifiglio" <(E-Mail Removed)> wrote in
message news:9p%_b.11464$(E-Mail Removed)...
> hi Douglas,
>
> Below i am providing you with a quick copy and paste from the docs. For a
> working example of how this can work for you, go to :
>

http://www.bluevisionsoftware.com/We...px?Name=PayPal
>
>
> Requests and Responses in the .NET Framework
> The .NET Framework uses specific classes to provide the three pieces of
> information required to access Internet resources through a

request/response
> model: the Uri class, which contains the URI of the Internet resource you
> are seeking; the WebRequest class, which contains a request for the
> resource; and the WebResponse class, which provides a container for the
> incoming response.
>
> Client applications create WebRequest instances by passing the URI of the
> network resource to the WebRequest.Create method. This static method

creates
> a WebRequest instance for a specific protocol, such as HTTP. The

WebRequest
> instance that is returned provides access to properties that control both
> the request to the server and access to the data stream that is sent when
> the request is made. The GetResponse method on the WebRequest instance

sends
> the request from the client application to the server identified in the

URI.
> In cases in which the response might be delayed, the request can be made
> asynchronously using the BeginGetResponse method on the WebRequest

instance,
> and the response can be returned at a later time using the EndGetResponse
> method.
>
> The GetResponse and EndGetResponse methods return a WebResponse instance
> that provides access to the data returned by the server. Because this data
> is provided to the requesting application as a stream by the
> GetResponseStream method, it can be used in an application anywhere data
> streams are used.
>
> The WebRequest and WebResponse classes are the basis of pluggable
> protocols-an implementation of network services that enables you to

develop
> applications that use Internet resources without worrying about the

specific
> details of the protocol that each resource uses. Descendant classes of
> WebRequest are registered with the WebRequest class to manage the details

of
> making the actual connections to Internet
>
>
> As an example, the HttpWebRequest class manages the details of connecting

to
> an Internet resource using HTTP. By default, when the WebRequest.Create
> method encounters a URI that begins with "http:" or "https:" (the protocol
> identifiers for HTTP and secure HTTP), the WebRequest instance that is
> returned can be used as is, or it can be typecast to HttpWebRequest to
> access protocol-specific properties. In most cases, the WebRequest

instance
> provides all the necessary information for making a request.
>
> Any protocol that can be represented as a request/response transaction can
> be used in a WebRequest. You can derive protocol-specific classes from
> WebRequest and WebResponse and then register them for use by the

application
> with the static WebRequest.RegisterPrefix method.
>
> When client authorization for Internet requests is required, the

Credentials
> property of the WebRequest supplies the necessary credentials. These
> credentials can be a simple name/password pair for basic HTTP or digest
> authentication, or a name/password/domain set for NTLM or Kerberos
> authentication. One set of credentials can be stored in a

NetworkCredentials
> instance, or multiple sets can be stored simultaneously in a

CredentialCache
> instance. The CredentialCache uses the URI of the request and the
> authentication scheme that the server supports to determine which
> credentials to send to the server.
>
>
>
>
>
> "DOUGLAS HEESTAND" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > After more fiddling it seems I can't get it to co-exist with form
> > validation. Changing the value of the "onSubmit" property of the form
> > causes the last validation to be bypassed. If I try to change the
> > value of the "onClick" property of the submit button I get something
> > like this when it is rendered into HTML:
> >
> > <input type="submit" name="btnSubmit" value="Submit"
> >

>

onclick="javascript:document.forms[0].action='http://othersite.com/otherform
> .html;if
> > (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); "
> > language="javascript" id="btnSubmit" />
> >
> > So it submits before validating and I can't make it validate first. I
> > could create a custom javascript function but that is starting to get
> > hokey and just plain ugly. I'd rather use a vanilla html form at that
> > point!
> >
> > I can't believe ASP.NET can't handle this situation!
> >
> > -Doug

>
>



 
Reply With Quote
 
DOUGLAS HEESTAND
Guest
Posts: n/a
 
      02-26-2004
Exactly what I was looking for. Thanks so much!
 
Reply With Quote
 
Scott Hill
Guest
Posts: n/a
 
      02-26-2004

This didnt work for me. It always gives my a javascript error.

error: "Microsoft JScript runtime error: Object doesn't support this
property or method"


Here is the code I am trying:

protected System.Web.UI.WebControls.Button butSubmit;

butSubmit.Attributes.Add("onClick",

"javascript:document.forms[0].action='http://localhost/bpass/test3.aspx'
;document.forms[0].__VIEWSTATE=''");



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Form Post to another URL from in HTML FRAME Josh ASP .Net 0 04-15-2008 03:23 PM
Multiple Form Post Using Javascript - Empty Post from FF Adam Javascript 8 11-24-2005 12:03 PM
How do I post hidden variables to another form from a popup? aaa ASP .Net 2 04-12-2005 01:45 PM
How do I post hidden variables to another form from a popup? aaa ASP .Net Web Controls 2 04-12-2005 01:45 PM



Advertisments