ASPX Post to another page

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
 
B

Bob Barrows [MVP]

Mark said:
I have created the following code to post data from a textbox to
another page (post.aspx).

There was no way for you to know it, but this is a classic asp newsgroup.
While you may be lucky enough to find a dotnet-knowledgeable person here who
can answer your question, you can eliminate the luck factor by posting your
question to a group where those dotnet-knowledgeable people hang out. I
suggest microsoft.public.dotnet.framework.aspnet.

Unfortunately, I'm still finding my way around .Net, and was unaware that
this method could be used to redirect a request (I thought one had to do
server.transfer or response.redirect). Hopefully someone at the aspnet group
can help you.

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,531
Members
45,005
Latest member
MellisaSti

Latest Threads

Top