Click to See Complete Forum and Search --> : Building QueryStrings on a Redirect + How to send post data?


Xefan
12-13-2006, 05:11 AM
Hi there,
I have two queries, I'm fairly new to ASP but not programming in general, I've had a look through Google and such but ASP.NET seems to get all the hits there.

My first query is, is there a proper way to build a query string to be sent as part of a response.redirect or are you meant to just manually build it using a string and then submit this manually built URL+QueryString string as your response.redirect target?

My second query is, is it possible to redirect to a different ASP page and submit a POST data QueryString? I have a login form on my site which submits the form to a seperate ASP page to process the login, I also have a signup form, when signup is complete and signup details have been validated and recorded into the database I'd like to just submit the username and password from the completed signup form to my existing login processing asp file which accepts POST data (because I don't want the username and password in the QueryString!).

Hope someone can help!

Thanks.

so_is_this
12-13-2006, 09:23 AM
Attaching a string to the url on redirect is the only way to send GET-type data from Classic ASP. There is no supplied way to send POST-type data from Classic ASP. A Client Proxy is required to do that. Postulating here... On a Windows server, perhaps Classic ASP could instantiate the ActiveX Browser Control and use that to build and submit a form.

lmf232s
12-13-2006, 10:02 AM
Xefan,
Not sure if this is what your after but...

Question 1:
You dont have to manual build the query string and place static text on the page. You can build this by appending values to the string or by calling a function.

You can build the query string on page load or a post back.
Here is a simple example.

Dim sLink : sLink = "NewPage.asp"
Dim bRet : bRet = True
Dim sId : sId = '1984' This could easily be a value populated from a DB look up or something.
Dim sLoc : sLoc = "Home"

Response.Redirect(sLink & BuildQueryString(sRet, sId, sLoc))

Function BuildQueryString(sRet, sId, sLoc)
Dim sParm : sPart = ""

If bRet = True Then
sParm = "?Id=" & sId & "Loc=" & sLoc
Else
sParm = ""
End If

BuildQueryString = sParam
End Function

OR

Response.redirect("NewPage.asp?Id=1212&Loc=Home")



Question 2:
Maybe something like this

Page1.asp

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>

<form name="frmPost" method="Post" action="Page2.asp">
<input type="text" name="txtUserName"><br>
<input type="text" name="txtPassword"><br>
<input type="submit" name="cmdPostData" value="Post Form"><br>
</form>

</BODY>
</HTML>

Page2.asp

<%Option explicit%>

<%
With Response
.Write "Here are the Posted Values:<br>"
.Write Request.Form("txtUserName") & "<br>"
.Write Request.Form("txtPassword") & "<br>"
End With
%>

Xefan
12-13-2006, 05:00 PM
Hi all, thanks for the replies, so_is_this' response was more what I was after lmf232s, but thanks also :) It's not so much that I'm unable to do what I need to do but more that I wanted to know if there was a better way to do it that was more friendly to the modern programming paradigm - i.e. better code reuse and such but unfortunately it seems not and that I was on the right track with my initial solutions ;) Thanks again to both of you!