Solved

update database before post data to another page

Posted on 2011-02-27
10
819 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 20

Expert Comment

by:informaniac
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Accepted Solution

by:
John Claes earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks all for your reply
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now