0

I have to integrate a C# web application (App1, a shopping cart) with another C# web application (App2 - a checkout page) that integrates with a payment service (PaymentApp).

  • Neither App2 or PaymentApp can be changed.
  • App2 must receive data and at least one file via a POST request.
  • PaymentApp only accepts POSTs from App2.

So, I add a button in App1 to make it post to App2 like this...

<asp:Button ID="Button1" runat="server" PostBackUrl="App2" onclick="Button1_Click"/>

But when I do that Button1_Click (which contains server side pre-submission processing) never gets called. Note: server side processing can't be transferred to the client side, that's why it's on the server!

So, how can I POST both data and files to App2 and still get my Button1_Click event in App1 (or some other event in App1) to execute prior to the POST taking place?

I've read countless posts about using HttpWebRequest, WebClient, Server.Transfer, StringBuilder etc. but none of the examples fit this scenario. I'm beginning to think it can't be done but that's too defeatist. With the combined knowledge and widsom of StackOverflow this must be possible.

cymorg
  • 534
  • 2
  • 10
  • 27

1 Answers1

0

The PostbackUrl property (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.postbackurl%28v=vs.110%29.aspx) allows you to post to a different page:

The URL of the Web page to post to from the current page when the Button control is clicked. The default value is an empty string (""), which causes the page to post back to itself.

If you set this to App2, the form will be submitted to there and not to your own page, thus the handler on your own page will never be called.

You could make a post to App2 from the server side of your postback handler on App1 instead.

w5l
  • 5,341
  • 1
  • 25
  • 43