Click here to Skip to main content
15,891,730 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi. friends.
I have one .aspx page and I am integrating sagepay payment in asp.net.

I have four hidden field and one button control. form tag has action attribute has been set as URL of sagepay and method="post". When I click on button control, server code is not executing and it redirects to sage pay. I need to execute button click event so before redirecting user to sagepay website, I need to store order information in database table.

can anybody know how to fix this issue? Or any other way to integrate sagepay in asp.net.

Thanks
Imrankhan
Posted
Comments
NAGARAJ N MACHAKNUR 23-Mar-14 0:43am    
Hi Imrankhan,

I got requirement same like your question. Can you share me solution.

Advance Thank you

Regards
Nagaraj

Show us the applicable code that already have.
 
Share this answer
 
hi,
Use the markup given below

XML
<form id="form2" runat="server">
      <input type="hidden" runat="server" name="VPSProtocol" value="2.23" />
      <input type="hidden" runat="server" name="TxType" value="PAYMENT" />
      <input type="hidden" runat="server" name="Vendor" value="vendorname" />
      <input type="hidden" runat="server"name="Crypt" value="orderInfo" />
<asp:Button ID="btnTest" runat="server" Text="Test SagePay" runat="server" OnClick="onclick_click" />
      </form>


If you want to perform some database operation do that in onclick eventhandler, then use Response.Redirect("https://test.sagepay.com/gateway/service/vspform-register.vsp[^]").

Hope this will help.
 
Share this answer
 
No. That will not help me. I want to pass hidden field value to that server using POST method. If I use response.redirect method then values are not passed to the given url that's why I used action attribute in form tag and method as POST.

Thanks
Imrankhan
 
Share this answer
 
One way of doing this is:
1) Add javascript to client-end to post the form instead of HTML
XML
<script language="javascript" type="text/javascript">
        function PostDForm() {
            var form = document.createElement("form");
            form.setAttribute("method", "post");
            form.setAttribute("action", "test.aspx");

            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("name", "idOfHiddenField");
            hiddenField.setAttribute("value", "valueOfHiddenField");
            form.appendChild(hiddenField);
            document.body.appendChild(form);
            form.submit();
        }
    </script>


2) Add button to asp.net page:
<asp:Button ID="btn" runat="server" Text="Click Me" onclick="btn_Click" />
3) Add following code to button click event:
C#
protected void btn_Click(object sender, EventArgs e)
    {
        //Write code here to save your data to database

        ClientScript.RegisterStartupScript(this.GetType(),"keyToPostDFormFunction", "<script>PostDForm();</script>");
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900