Solved

Issue with Creating a Form on the Fly

Posted on 2013-10-30
3
232 Views
Last Modified: 2013-11-30
Hi

Due to ASP.net now allowing a Form within an ASP:Form for the payment provider I am creating a form on the fly and using JQuery to trigger this

Everything is fine until the amount which is being problematic:

Dim Url As String = "https://MyPaymentProvider"
            Dim formId As String = "myForm1"

            Dim htmlForm As New StringBuilder()
            htmlForm.AppendLine("<html>")
            htmlForm.AppendLine([String].Format("<body onload='document.forms[""{0}""].submit()'>", formId))
            htmlForm.AppendLine([String].Format("<form id='{0}' method='POST' action='{1}'>", formId, Url))
            htmlForm.AppendLine("<input type='hidden' name='PSPID' value='MyCode'>")
            htmlForm.AppendLine([String].Format("<input type='hidden' name='ORDERID' value='{0}'>", orderid))
            htmlForm.AppendLine([Int32].Parse("<input type='hidden' name='AMOUNT' value='{0}'>", amount))
            htmlForm.AppendLine("<input type='hidden' name='CURRENCY' value='GBP'>")
            htmlForm.AppendLine("<input type='hidden' name='LANGUAGE' value='en_US'>")
            htmlForm.AppendLine("</form>")
            htmlForm.AppendLine("</body>")
            htmlForm.AppendLine("</html>")

            HttpContext.Current.Response.Clear()
            HttpContext.Current.Response.Write(htmlForm.ToString())
            HttpContext.Current.Response.[End]()

Open in new window


The issue I am having is with this line of code htmlForm.AppendLine([Int32].Parse("<input type='hidden' name='AMOUNT' value='{0}'>", amount)) and it keeps throwing the following error:
An undefined NumberStyles value is being used.
Parameter name: style

Amount is an int32 variable as the payment provider expects this as the decimal amount multiplied by 100

If anyone can help it would be most appreciated
0
Comment
Question by:TPLLimited
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39611969
The Int32.Parse method takes a string containing a number as its first parameter.

You should be doing:
htmlForm.AppendLine([String].Format("<input type='hidden' name='AMOUNT' value='{0}'>", [Int32].Parse(amount)))

Open in new window

0
 

Author Comment

by:TPLLimited
ID: 39612012
Hi

Thanks for the response

I did try that but the payment provider then refuses the payment due to it not being non numeric

Error on Payment provider website:

amount too long or not numeric: length 46 MAX:15
0
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 39612485
If you out the contents of htmlForm to the screen instead of submitting to the provider, what does the input tag for Amount look like? Are there extra spaces in the value property? Is the amount a valid number?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

912 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

17 Experts available now in Live!

Get 1:1 Help Now