Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass the Request string when calling Reponse.redirect? 2

Status
Not open for further replies.

JNeave

Programmer
Jan 28, 2002
125
GB
My page contains a form, which action's itself. If the submit button was pressed, a hidden field is marked with goSubmit.

In this situation the data in the form must be passed to the next form. is there any was to simply pass the request string's parameters (?bob=bill, etc.) to another page? or do I have to fill all the data myself in with lots of code or create the string programatically?

cheers,

Jim.
 
Hello,
<%@ Language=VBScript %>
<%
' Get passed page variables from passing form
varid1= Request.QueryString(&quot;varid1&quot;)
varid2= Request.QueryString(&quot;varid2&quot;)

' Get what button user selected
strCmd = ucase(Request.Form(&quot;cmdSelect&quot;))

Select case strCmd
Case &quot;TEST Response.Redirect &quot;Yourpagehere.asp?varid1=&quot; + varid1 + &quot;&varid2=&quot; + varid2
Case &quot;TEST2&quot;

... more code here
end select
%>
<HTML>
<HEAD>
</HEAD>

<body topmargin=&quot;0&quot; leftmargin=&quot;0&quot;>
<!-- #include file=&quot;includes/phead.inc&quot;-->
<h1>My Page Header here</h1>

<!--Create your button -->
<input TYPE=&quot;SUBMIT&quot; VALUE=&quot;TEST&quot; id=&quot;TEST&quot; name=&quot;cmdSelect&quot;>
<input TYPE=&quot;SUBMIT&quot; VALUE=&quot;TEST2&quot; id=&quot;TEST2&quot; name=&quot;cmdSelect&quot;>

</Body>
</Html>
 
A simpler way to do this is to grab the entire querystring and concatenate it back onto the new URL. This way you won't need to hardcode in your variables. Since I am forgetful thats usually a good thing :)
Code:
<%
'get the querystring
Dim qs
qs = Request.QueryString

Select Case Request.QueryString(&quot;YourHiddenField&quot;)
   Case &quot;goSubmit&quot;
      Response.Redirect &quot;yourpagehere.asp?&quot; & qs
   Case '...
      '... more code here
   Case Else
      '... and so on
End Select
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Well, it would be nice if Request.QueryString didn't come back blank.... :(

Response.write Request.Form(&quot;hidState&quot;) & &quot;.<BR>&quot;
Response.write Request.QueryString(&quot;hidState&quot;) & &quot;.<BR>&quot;
Response.write Request.QueryString.Count

The output from that is

goSubmit.
.
0

The data's getting there, but QueryString is broke?

cheers,

Jim.
 
OK. weirdness

It all works if I use Request.Form instead of Request.Querystring.

Except on the next page, SearchNew.asp, where only Request.Querystring works.

er.

Right, next questtion.

apart from goSubmit, it also returns goAlpha to itself.
This is for when the ABC, DEF, GHI, etc., combo box is changed, it requeries the contents of the the location combobox.

But then any other search criteria you enter has vanished. Which I expected.

What I didn't expect is that you can't see ANY of the client side controls such as INPUT text's and radio's. So I can't fill that data back in server side. And I don't know how to pass the data to a client side JScript. I don't really want to create ALL my form controls with VBScripts server side, I would like to just be able to set their .value properties from the Request string.

Is this possible?

cheers,

Jim.

 
ah, sorry, Request.QueryString is for getting form data from a GET request, Request.Form is for getting data from a POST request. So depending on whether your form method=POST or method=GET or you build the string by itself as part of an addr (ie you will use, respectively, Request.Form, Request.QueryString, Request.QueryString.
With radio and checkbox types you receive back only the selected value, so you will need to rebuild the controls and do an if-check to see which one is selected. With multiple selections from a checkbox you will receive a comma-delimited list of values, so here is an example :)
Code:
MyPage.asp
<%
Option Explicit
%>
<html>
<body>
<form method=GET action=&quot;myPage.asp&quot;>
Text: <input type=&quot;text&quot; name=&quot;txtGeneric&quot; value=&quot;<%=Request.QueryString(&quot;txtGeneric&quot;)%>&quot;><br>
A: <input type=&quot;radio&quot; name=&quot;radGeneric&quot; value=&quot;A&quot;<% If Request.QueryString(&quot;radGeneric&quot;) = &quot;A&quot; Then Response.Write &quot; selected&quot;%>><br>
B: <input type=&quot;radio&quot; name=&quot;radGeneric&quot; value=&quot;B&quot;<% If Request.QueryString(&quot;radGeneric&quot;) = &quot;A&quot; Then Response.Write &quot; selected&quot;%>><br>
C: <input type=&quot;radio&quot; name=&quot;radGeneric&quot; value=&quot;C&quot;<% If Request.QueryString(&quot;radGeneric&quot;) = &quot;A&quot; Then Response.Write &quot; selected&quot;%>><br>
<br>
One: <input type=&quot;checkbox&quot; name=&quot;chkGeneric&quot; value=&quot;One&quot;<% If InStr(Request.QueryString(&quot;chkGeneric&quot;,&quot;One&quot;) Then Response.Write checked%>><br>
Two: <input type=&quot;checkbox&quot; name=&quot;chkGeneric&quot; value=&quot;Two&quot;<% If InStr(Request.QueryString(&quot;chkGeneric&quot;,&quot;Two&quot;) Then Response.Write checked%>><br>
Three: <input type=&quot;checkbox&quot; name=&quot;chkGeneric&quot; value=&quot;Three&quot;<% If InStr(Request.QueryString(&quot;chkGeneric&quot;,&quot;Three&quot;) Then Response.Write checked%>><br>
<br>
<select name=&quot;selGeneric&quot;>
	<option value=&quot;Blue&quot;<% If Request.QueryString(&quot;selGeneric&quot;) = &quot;Blue&quot; Then Response.Write &quot; selected&quot;%>> Blue </option>
	<option value=&quot;Green&quot;<% If Request.QueryString(&quot;selGeneric&quot;) = &quot;Green&quot; Then Response.Write &quot; selected&quot;%>> Green </option>
	<option value=&quot;Red&quot;<% If Request.QueryString(&quot;selGeneric&quot;) = &quot;Red&quot; Then Response.Write &quot; selected&quot;%>> Red </option>
</select><br>
<input type=&quot;submit&quot;>
</form>
The above code was on the fly, but it should work as an example. A prettier way to do this would be to have the values in arrays and loop through creating each set of controls from the array. It is just as much, if not more, work for the server, but looks prettier.

Now one problem you may be having with form data disappearing is that when your doing your Response.redirect you are losing all the form data from the previous page that you didn't specify in the query string for the url. If you switch to method=GET you can grab the entire querystring as I posted above without having to hardcode all the possible elements they could be passing from.

An option here would be to embed your pages in one file inside functions and do you select case statement to decide which function to call. This way you will always have your form info available. Rather than write another example, if your interested I posted a heavily commented file that is three or for pages in one as a FAQ in the ASP forum, it's under ASP 102.
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Wow, thanks mate!

That all works really well. Will give your FAQ a read too.

cheers,

Jim.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top