Solved

update database before post data to another page

Posted on 2011-02-27
10
857 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Database ERD 4 80
error starting form builder in 11g 2 27
CSS for Popup in ASP.NET 4 18
Displaying images within Access Form 6 19
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.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

733 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