M
Mark
I have created the following code to post data from a textbox to another page
(post.aspx). I created the lblResponse to prove to myself that something was
actually getting posted, and that works. However when you click the button
it does not take you to the post.aspx page. It just refreshes the page! Any
ideas whats up with this?
Sub post_click(ByVal s As Object, ByVal e As EventArgs)
Dim objRequest As HttpWebRequest
Dim strRequest As String
Dim arrRequest As Byte()
Dim objUTF8Encoding As UTF8Encoding
Dim strmRequest As Stream
Dim objResponse As HttpWebResponse
Dim srResponse As StreamReader
' Initialize request object
objRequest =
CType(WebRequest.Create("http://localhost/rsfront/post.aspx"), HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentType = "application/x-www-form-urlencoded"
'objRequest.AllowAutoRedirect = True
' Create request body
strRequest = "Dept=" & Server.UrlEncode(txtDept1.Text)
objUTF8Encoding = New UTF8Encoding
arrRequest = objUTF8Encoding.GetBytes(strRequest)
' Add body to request
objRequest.ContentLength = arrRequest.Length
strmRequest = objRequest.GetRequestStream()
strmRequest.Write(arrRequest, 0, arrRequest.Length)
strmRequest.Close()
' Get response
objResponse = objRequest.GetResponse()
srResponse = New StreamReader(objResponse.GetResponseStream(),
Encoding.ASCII)
lblResponse.Text = srResponse.ReadToEnd()
srResponse.Close()
End Sub
(post.aspx). I created the lblResponse to prove to myself that something was
actually getting posted, and that works. However when you click the button
it does not take you to the post.aspx page. It just refreshes the page! Any
ideas whats up with this?
Sub post_click(ByVal s As Object, ByVal e As EventArgs)
Dim objRequest As HttpWebRequest
Dim strRequest As String
Dim arrRequest As Byte()
Dim objUTF8Encoding As UTF8Encoding
Dim strmRequest As Stream
Dim objResponse As HttpWebResponse
Dim srResponse As StreamReader
' Initialize request object
objRequest =
CType(WebRequest.Create("http://localhost/rsfront/post.aspx"), HttpWebRequest)
objRequest.Method = "POST"
objRequest.ContentType = "application/x-www-form-urlencoded"
'objRequest.AllowAutoRedirect = True
' Create request body
strRequest = "Dept=" & Server.UrlEncode(txtDept1.Text)
objUTF8Encoding = New UTF8Encoding
arrRequest = objUTF8Encoding.GetBytes(strRequest)
' Add body to request
objRequest.ContentLength = arrRequest.Length
strmRequest = objRequest.GetRequestStream()
strmRequest.Write(arrRequest, 0, arrRequest.Length)
strmRequest.Close()
' Get response
objResponse = objRequest.GetResponse()
srResponse = New StreamReader(objResponse.GetResponseStream(),
Encoding.ASCII)
lblResponse.Text = srResponse.ReadToEnd()
srResponse.Close()
End Sub