[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

heestand

2/26/2004 4:24:00 PM

How do you add a textbox in code and add them to a particular form? I
am using WebRequest.Create (vb.net) to send a form request to
authorize.net for credit card processing. They require that one of
the fields is the account password. I have to send that as part of my
form but I don't want to have it visible to the user so a hidden form
field won't work. Is there a way to create the control in code, in
the proper form, before I send the form? Here is my code for sending
the form (it is attached to the onClick event for my submit button).

Thanks in advance!

---------------
Code
---------------
Dim objRequest As HttpWebRequest
Dim strPost As String
Dim strRequest As String
Dim strResult As String
Dim arrRequest As Byte()
Dim objUTF8Encoding As UTF8Encoding
Dim strmRequest As Stream
Dim objResponse As HttpWebResponse
Dim srResponse As StreamReader

'####INSERT CODE TO CREATE PASSWORD TEXTBOX HERE##########

strPost = Request.Form().ToString()

objRequest = CType(WebRequest.Create("https://secure.authorize.net/gateway/transact...),
HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentType = "application/x-www-form-urlencoded"
strRequest = strPost
objUTF8Encoding = New UTF8Encoding
arrRequest = objUTF8Encoding.GetBytes(strRequest)
objRequest.ContentLength = strPost.Length
strmRequest = objRequest.GetRequestStream()
strmRequest.Write(arrRequest, 0, arrRequest.Length)
strmRequest.Close()

objResponse = objRequest.GetResponse()
srResponse = New StreamReader(objResponse.GetResponseStream(),
Encoding.ASCII)
strResult = srResponse.ReadToEnd()
1 Answer

Ken Cox [MS MVP]

2/27/2004 3:12:00 AM

0

Hi Douglas,

Another approach is to use the WebClient class. It lets you add anything you
want to the upload values collection. You could get some parts from the form
and add your own.

Sub DoPost()
Dim uriString As String = _
"http://localhost/p4320work/receiver.aspx"
' Create a new WebClient instance.
Dim myWebClient As New WebClient
' Create a new NameValueCollection instance to hold
'some custom parameters to be posted to the URL.
Dim myNameValueCollection As New NameValueCollection
Dim name As String = ""
name = TextBox1.Text
Console.Write("Age:")
Dim age As String
age = TextBox2.Text
Dim privatedata As String
privatedata = "mysecretstuff"
' Add necessary parameter/value
'pairs to the name/value container.
myNameValueCollection.Add("Name", name)
myNameValueCollection.Add("Age", age)
myNameValueCollection.Add("Private", privatedata)
' Upload the NameValueCollection.
Dim responseArray As Byte() = myWebClient.UploadValues _
(uriString, "POST", myNameValueCollection)
' Decode and display the response.
Label1.Text = "Response received was :" & _
Encoding.ASCII.GetString(responseArray)
End Sub

Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto

"DOUGLAS HEESTAND" <heestand@alumni.duke.edu> wrote in message
news:8e66a971.0402260824.3a787b42@posting.google.com...
> How do you add a textbox in code and add them to a particular form? I
> am using WebRequest.Create (vb.net) to send a form request to
> authorize.net for credit card processing. They require that one of
> the fields is the account password. I have to send that as part of my
> form but I don't want to have it visible to the user so a hidden form
> field won't work. Is there a way to create the control in code, in
> the proper form, before I send the form? Here is my code for sending
> the form (it is attached to the onClick event for my submit button).
>
> Thanks in advance!
>
> ---------------
> Code
> ---------------
> Dim objRequest As HttpWebRequest
> Dim strPost As String
> Dim strRequest As String
> Dim strResult As String
> Dim arrRequest As Byte()
> Dim objUTF8Encoding As UTF8Encoding
> Dim strmRequest As Stream
> Dim objResponse As HttpWebResponse
> Dim srResponse As StreamReader
>
> '####INSERT CODE TO CREATE PASSWORD TEXTBOX HERE##########
>
> strPost = Request.Form().ToString()
>
> objRequest =
> CType(WebRequest.Create("https://secure.authorize.net/gateway/transact...),
> HttpWebRequest)
> objRequest.Method = "POST"
> objRequest.ContentType = "application/x-www-form-urlencoded"
> strRequest = strPost
> objUTF8Encoding = New UTF8Encoding
> arrRequest = objUTF8Encoding.GetBytes(strRequest)
> objRequest.ContentLength = strPost.Length
> strmRequest = objRequest.GetRequestStream()
> strmRequest.Write(arrRequest, 0, arrRequest.Length)
> strmRequest.Close()
>
> objResponse = objRequest.GetResponse()
> srResponse = New StreamReader(objResponse.GetResponseStream(),
> Encoding.ASCII)
> strResult = srResponse.ReadToEnd()