Solved

update database before post data to another page

Posted on 2011-02-27
10
844 Views
Last Modified: 2013-12-25
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

0
Comment
Question by:viola123
10 Comments
 
LVL 6

Author Comment

by:viola123
ID: 34994272
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
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 34994355
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
 
LVL 6

Author Comment

by:viola123
ID: 34994366
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 20

Expert Comment

by:informaniac
ID: 34994582
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
 
LVL 6

Author Comment

by:viola123
ID: 34994645
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
 
LVL 10

Accepted Solution

by:
John Claes earned 250 total points
ID: 34995063
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
 

Expert Comment

by:pavan_kumar_kokkiragedda
ID: 34995862
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
 
LVL 6

Author Comment

by:viola123
ID: 35003628
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
 

Assisted Solution

by:pavan_kumar_kokkiragedda
pavan_kumar_kokkiragedda earned 250 total points
ID: 35004449
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
 
LVL 6

Author Closing Comment

by:viola123
ID: 35412676
thanks all for your reply
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Foxpro errors 4 34
Obtain cell value using column ID in DataGrid using VB.NET 2 19
RLDC Reporting in Visual studio 11 16
No Data for DropDown List 2 26
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question