update database before post data to another page

Hi,

below is my asp.net page. clicking button1 posts all hidden input data to a paypal page and redirect to the paypal page.

However, I need to update database before post these data to another page and redirect. It means in the button1_Click event I need to update database first and and then post data + redirect to paypal page

anyone can show me how to do it?
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="posturl.aspx.cs" Inherits="testWeb.posturl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="hidden" name="cmd" value="_xclick" />
        <input type="hidden" name="business" value="xxx@yahoo.com" />
        <input type="hidden" name="lc" value="AU" />
        <input type="hidden" name="item_name" value="Order Item 100000"/>
        <input type="hidden" name="amount" value="100.00" />
        <input type="hidden" name="currency_code" value="AUD" />
        <input type="hidden" name="button_subtype" value="services" />
        <input type="hidden" name="no_note" value="0" />

        <asp:Button ID="Button1" runat="server" Text="Button" 
            PostBackUrl="https://www.paypal.com/cgi-bin/webscr" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>

Open in new window

LVL 6
viola123Asked:
Who is Participating?
 
John ClaesSenior .Net Consultant & Technical AnalistCommented:
Then we need 2 things

Question 1 : Post data :
(See answer of agarwalrahul)
You need to add the Id attribute and runat="server" attribute to every field you'll need to be posted.
After clicking the Button these fields will post their value towards the server.

Question 2
At server Side you do what you need to do to your database
But then You need to Redirect(using post /Push Values?)


Example (using answer of Agarwalrahul for ease ;-) )


Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
          insert into DB
         dim Url as string
         Url ="https://www.paypal.com/cgi-bin/webscr?"
         Url =Url & "business=" & business.value
         Url =Url & "&lc=" & lc.value
         Url =Url & "&item_name=" & item_name.value
         response.redirect(Url )

regards
poor beggar
0
 
viola123Author Commented:
let's make the question simpler:

I need to post the data from button1_Click() and redirect to paypal page

How to do this?
0
 
Rahul AgarwalTeam LeaderCommented:
Add Id and Runat="Server" to each input field, by doing this you can access these field on Code behind page by using input field id.value and on button click save these field to DB and then response.redirect to "https://www.paypal.com/cgi-bin/webscr"

For e.g:

<input type="hidden" id="Input1" runat="Server" name="cmd" value="_xclick" />

Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
         dim input as string=Input1.value
          insert into DB
         response.redirect("https://www.paypal.com/cgi-bin/webscr")
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
viola123Author Commented:
Hi, agarwalrahul:

I don't need save those hidden filelds data in database. I meant I need to update database for other reason. I just need to do SOMETHING in codebehind before post data

forget the database update. I need to post data to the paypal url and then redirect the the paypal page with all posted data populated in that page. not just response.redirect("https://www.paypal.com/cgi-bin/webscr") because this url itself does not show any data.
0
 
Obadiah ChristopherCommented:
So as of now wht is hapening? 2ndly r u askin how to update the paypal page from ur page? Tht's not possible.
0
 
viola123Author Commented:
Hi, informaniac:

below is a html page, clicking the submit button will post all hidden fileds data to https://www.paypal.com/cgi-bin/webscr and the page will be directed to that paypal page and all posted data is displayed in that paypal page.

my question is how to achieve this using asp.net server-side button click event. yes, two things:
1. post data
2. redirect to the page and display posted data in that page

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick"/>
<input type="hidden" name="business" value="yingtuo@yahoo.com"/>
<input type="hidden" name="lc" value="AU"/>
<input type="hidden" name="item_name" value="Order Item 100000">
<input type="hidden" name="amount" value="100.00"/>
<input type="hidden" name="currency_code" value="AUD"/>
<input type="hidden" name="button_subtype" value="services"/>
<input type="hidden" name="no_note" value="0"/>
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest"/>
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online."/>
<img alt="" border="0" src="https://www.paypal.com/en_AU/i/scr/pixel.gif" width="1" height="1"/>
</form>
0
 
pavan_kumar_kokkirageddaCommented:
Hi,
Instead of using the "postbackurl" attribute, you can go for a button click event,do the db changes and then redirect to the desired page using Response.Redirect.

0
 
viola123Author Commented:
Hi,

this url display only login page without post data. if you simply use response.redirect(), it could not display those posted data in destination url.

I don't want to post data and hit the login page by using response.redirect(). I need those posted data page displayed in the destination url.

using 'POST' and then use 'GET' does not work
0
 
pavan_kumar_kokkirageddaCommented:
In that case,
you can try going for a java script function that does the db changes  using ajax, and set this function as the value for the "OnClientClick" event of the button.

hope this helps

Regards,
Pavan
0
 
viola123Author Commented:
thanks all for your reply
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.