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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting URL of the page and passing it to other page 5

Status
Not open for further replies.

zxcdf5je

Programmer
Apr 1, 2005
86
US
hi there,
I have this page which lists all the users name and they can be edited deleted and updated.The page which does that is 2.asp and the page which actually lists all the users is 1.asp.
when i delete a particular user by using 2.asp ,after delteing the users name it redirects me to the first page of 1.asp and i again have to go do 28th page to proceed ahead with other users..is there any way i could catch that page number /page and make the user return to the page from where they came from?

Hope u are understanding what i want..
help needed..pleaseeeee

-Smita

1.asp uses this code to catch url:
'-------------------------------
' list Navigation begin
'-------------------------------
bEof = rs.eof
if not(rs.EOF and iPage=1) then
if iPage = 1 then
%>
<font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">Previous</font>
<%
else
%>
<a href="<%=file_name%>?<%=form_params%><%=sSortParams%>Formlist_Page=<%=iPage - 1%>#list"><font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">Previous</font></a>
<%
end if
response.write "&nbsp;[&nbsp;" & iPage & "&nbsp;]&nbsp;"

if bEof then
%>
<font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">Next</font>
<%
else
%>
<a href="<%=file_name%>?<%=form_params%><%=sSortParams%>Formlist_Page=<%=iPage + 1%>#list"><font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">Next</font></a>
<%
end if
end if
'-------------------------------
' list Navigation end
'-------------------------------

2.asp
has just a variable sActionField="1.asp"
which if delete update pressed would point to this variable and take it to the first page ..

hope that helps
 
Here is a reformatted page1. I didnt fix anything, just tried to change the format so it would be easier to look at... Most likely I broke something in the process. I'm only posting it because it will allow me to refer to something that I can read when suggesting a change.

Code:
<%@ Language=VBScript %>
<!-- #INCLUDE FILE="Common.asp" -->

<%
  sFileName = "listGrid.asp"
  sAction = GetParam("FormAction")
  sForm = GetParam("FormName")

  sFormTitle = "Search"
  action_page = "listGrid.asp"
  flds_company = GetParam("s_company")
  
  Dim rs
  Dim sWhere : sWhere = ""
  Dim sOrder : sOrder = ""
  Dim sSQL : sSQL = ""
  Dim sFormTitle: sFormTitle = "list"
  Dim HasParam : HasParam = false
  Dim iSort : iSort = ""
  Dim iSorted : iSorted = ""
  Dim sDirection : sDirection = ""
  Dim form_sorting : form_sorting = ""
  Dim sSortParams : sSortParams = ""
  Dim form_action : form_action = ""
  Dim iRecordsPerPage : iRecordsPerPage = 20
  Dim iCounter : iCounter = 0
  Dim iPage : iPage = 0
  Dim bEof : bEof = False
  Dim sActionFileName : sActionFileName = "listRecord.asp"

  Dim form_params : form_params = "s_company=" & ToURL(GetParam("s_company")) & "&"


'-------------------------------
' Build ORDER BY statement
'-------------------------------
  sOrder = " order by l.company Asc"
  iSort = GetParam("Formlist_Sorting")
  iSorted = GetParam("Formlist_Sorted")
  sDirection = ""
  if IsEmpty(iSort) then
    form_sorting = ""
  else
    if iSort = iSorted then
      form_sorting = ""
      sDirection = " DESC"
      sSortParams = "Formlist_Sorting=" & iSort & "&Formlist_Sorted=" & iSort & "&"
    else
      form_sorting = iSort
      sDirection = " ASC"
      sSortParams = "Formlist_Sorting=" & iSort & "&Formlist_Sorted=" & "&"
    end if
    if iSort = 1 then sOrder = " order by l.[indexid]" & sDirection
    if iSort = 2 then sOrder = " order by l.[list]" & sDirection
    if iSort = 3 then sOrder = " order by l.[company]" & sDirection
    if iSort = 4 then sOrder = " order by l.[fname]" & sDirection
    if iSort = 5 then sOrder = " order by l.[lname]" & sDirection
    if iSort = 6 then sOrder = " order by l.[city]" & sDirection
    if iSort = 7 then sOrder = " order by l.[state]" & sDirection
    if iSort = 8 then sOrder = " order by l.[zip]" & sDirection
  end if


'-------------------------------
' Build WHERE statement
'-------------------------------
  ps_company = GetParam("s_company")
  if not isEmpty(ps_company) then
    HasParam = true
    sWhere = "l.[company] like '%" & replace(ps_company, "'", "''") & "%'" & " or " & "l.[list] like '%" & replace(ps_company, "'", "''") & "%'" & " or " & "l.[city] like '%" & replace(ps_company, "'", "''") & "%'"
  end if

  if HasParam then
    sWhere = " WHERE (" & sWhere & ")"
  end if


'-------------------------------
' Build base SQL statement
'-------------------------------
  sSQL = "select [l].[ID] as l_ID, " & _
    "[l].[city] as l_city, " & _
    "[l].[company] as l_company, " & _
    "[l].[fname] as l_fname, " & _
    "[l].[indexid] as l_indexid, " & _
    "[l].[list] as l_list, " & _
    "[l].[lname] as l_lname, " & _
    "[l].[state] as l_state, " & _
    "[l].[zip] as l_zip " & _
    " from [list] l "


'-------------------------------
' Assemble full SQL statement
'-------------------------------
  sSQL = sSQL & sWhere & sOrder


'-------------------------------
' Process the link to the record page
'-------------------------------
form_action = sActionFileName


'-------------------------------
' Open the recordset
'-------------------------------
  openrs rs, sSQL


'-------------------------------
'Initialize page counter and records per page
'-------------------------------
  iRecordsPerPage = 20
  iCounter = 0


'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("Formlist_Page")
  if IsEmpty(iPage) then iPage = 1 else iPage = CLng(iPage)

  'What is this?
  'Is it to scroll forward to appropriate record?
  while not rs.eof and iCounter < (iPage-1)*iRecordsPerPage
    rs.movenext
    iCounter = iCounter + 1
  wend
  
  iCounter = 0
%>

<html>
<head>
<title>drain</title>
<meta name="GENERATOR" content="YesSoftware CodeCharge v.2.0.4 build 11/30/2001">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>

<body style="background-color: #ffffff; color: #000000">
 <!-- Display Search Form -->
 <table>
  <tr>
   <td valign="top">
    <form method="GET" action="<%= action_page %>" name="Search">
		 <input type="hidden" name="FormName" value="Search"><input type="hidden" name="FormAction" value="search">
      
     <table style="border-style: groove; border-width: 3">
      <tr>
       <td style="background-color: #800000; text-align: Center; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000" colspan="3">
        <font style="font-size: 12pt; color: #FFFFFF; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
         <a name="Search"><%=sFormTitle%></a>
        </font>	
       </td>
      </tr>      
      <tr>
       <td style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
        <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
         company
        </font>
       </td>
       <td style="background-color: #FFFFCC; border-style: inset; border-width: 1">
        <input type="text" name="s_company" maxlength="255" value="<%= ToHTML(flds_company) %>" size="50" >
       </td>
       <td >
        <input type="submit" value="Search">
       </td>
      </tr>
     </table>
		</form>
   </td>
  </tr>
 </table>
 
 <!-- Display Grid Form -->
 <table>
  <tr>
   <td valign="top">
    <table style="border-style: groove; border-width: 3">
     <!-- Title Row -->
     <tr>
      <td style="background-color: #800000; text-align: Center; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000" colspan="8">
       <font style="font-size: 12pt; color: #FFFFFF; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
        <a name="list"><%=sFormTitle%></a>
       </font>
      </td>
     </tr>
     
     <!--  Column Headers Row -->
     <tr>
      <td style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
       <font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
        <a href="<%=sFileName%>?<%=form_params%>Formlist_Sorting=1&Formlist_Sorted=<%=form_sorting%>&">indexid</a>
       </font>
      </td>
      <td style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
       <font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
        <a href="<%=sFileName%>?<%=form_params%>Formlist_Sorting=2&Formlist_Sorted=<%=form_sorting%>&">list</a>
       </font>
      </td>
      <td style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
       <font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
        <a href="<%=sFileName%>?<%=form_params%>Formlist_Sorting=3&Formlist_Sorted=<%=form_sorting%>&">company</a>
       </font>
      </td>
      <td style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
       <font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
        <a href="<%=sFileName%>?<%=form_params%>Formlist_Sorting=4&Formlist_Sorted=<%=form_sorting%>&">fname</a>
       </font>
      </td>
      <td style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
       <font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
        <a href="<%=sFileName%>?<%=form_params%>Formlist_Sorting=5&Formlist_Sorted=<%=form_sorting%>&">lname</a>
       </font>
      </td>
      <td style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
       <font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
        <a href="<%=sFileName%>?<%=form_params%>Formlist_Sorting=6&Formlist_Sorted=<%=form_sorting%>&">city</a>
       </font>
      </td>
      <td style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
       <font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
        <a href="<%=sFileName%>?<%=form_params%>Formlist_Sorting=7&Formlist_Sorted=<%=form_sorting%>&">state</a>
       </font>
      </td>
      <td style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
       <font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
        <a href="<%=sFileName%>?<%=form_params%>Formlist_Sorting=8&Formlist_Sorted=<%=form_sorting%>&">zip</a>
       </font>
      </td>
     </tr>
   
     <!-- Data Rows Go Here -->
<%
  if rs.eof then
    'create data row showing no records
%>
     <tr>
      <td colspan="8" style="background-color: #FFFFCC; border-style: inset; border-width: 1">
       <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
        No records
       </font>
      </td>
     </tr>
<%  
  else
    'create 1 data per record
    Do While Not rs.EOF And (iCounter < iRecordsPerPage)
%>
     <tr>
      <td style="background-color: #FFFFCC; border-style: inset; border-width: 1">
			 <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
			  <a href="listRecord.asp?ID=<%=GetValue(rs, "l_ID")%>&s_company=<%=ToURL(GetParam("s_company"))%>&Formlist_Page=<%=iPage%>#list">
			   <%=GetValue(rs, "l_indexid")%>
			  </a>
			  &nbsp;
			 </font>
			</td>
      <td style="background-color: #FFFFCC; border-style: inset; border-width: 1">
       <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
        <%=ToHTML(GetValue(rs, "l_list"))%>
        &nbsp;
       </font>
      </td>
      <td style="background-color: #FFFFCC; border-style: inset; border-width: 1">
       <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
        <%=ToHTML(GetValue(rs, "l_company"))%>
        &nbsp;
       </font>
      </td>
      <td style="background-color: #FFFFCC; border-style: inset; border-width: 1">
       <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
        <%=ToHTML(GetValue(rs, "l_fname"))%>
        &nbsp;
       </font>
      </td>
      <td style="background-color: #FFFFCC; border-style: inset; border-width: 1">
       <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
        <%=ToHTML( GetValue(rs, "l_lname"))%>
        &nbsp;
       </font>
      </td>
      <td style="background-color: #FFFFCC; border-style: inset; border-width: 1">
       <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
        <%=ToHTML(GetValue(rs, "l_city"))%>
        &nbsp;
       </font>
      </td>
      <td style="background-color: #FFFFCC; border-style: inset; border-width: 1">
       <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
        <%=ToHTML(GetValue(rs, "l_state"))%>
        &nbsp;
       </font>
      </td>
      <td style="background-color: #FFFFCC; border-style: inset; border-width: 1">
       <font style="font-size: 10pt; color: #000000; font-family: Arial, Tahoma, Verdana, Helvetica">
        <%=ToHTML(GetValue(rs, "l_zip"))%>
        &nbsp;
       </font>
      </td>
     </tr>
<%
    rs.MoveNext
    iCounter = iCounter + 1
	  Loop  
	end if
%>     
    </table>
   </td>
  </tr>
  
  <!-- List Navigation -->
  <tr>
   <td colspan="8" style="background-color: #CCCCCC; border-left: 1 solid #FFFFFF; border-right: 1 solid #000000; border-top: 1 solid #FFFFFF; border-bottom: 1 solid #000000">
    <font style="font-size: 10pt; color: #000000; font-weight: bold; font-family: Arial, Tahoma, Verdana, Helvetica">
     <a href="<%= form_action %>?&s_company=<%=ToURL(GetParam("s_company"))%>">Insert</a>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%
  bEof = rs.eof
  if not(rs.EOF and iPage=1) then
    if iPage = 1 then
      Response.Write " Previous "
    else
%>
     <a href="<%=file_name%>?<%=form_params%><%=sSortParams%>Formlist_Page=<%=iPage - 1%>#list">Previous</a>
<%
    end if
    
    Response.Write "&nbsp;[&nbsp;" & iPage & "&nbsp;]&nbsp;"

    if bEof then
      Response.Write " Next "
    else
%>
     <a href="<%=file_name%>?<%=form_params%><%=sSortParams%>Formlist_Page=<%=iPage + 1%>#list">Next</a>
<%
    end if
  end if
%>
    </font>
   </td>
  </tr>
 </table>
</body>
</html>
<%

cn.close
Set cn = nothing
%>
 
OK, I see the type mismatch you were talking about.

You said it was in this line:
if IsEmpty(iPage) then iPage = 1 else iPage = CLng(iPage)

Well, I'll take your word for that and suggest a change to this:

If Not IsNumeric(iPage) Then
iPage = 1
Else
iPage = CLng(iPage)
End If
 
Of course this won't really fix the underlying problem.

The underlying problem is that the QueryString doesn't include the page number.
 
So why doesn't the QueryString include the page number?

Well I found this on page 2:
sActionFileName = " & request("s_company") & "&Formlist_Page=" & [red]request("iPage")[/red] &"#list"

Since iPage is a local variable, you won't be able to get it out of the QueryString!

Either just use the local variable like this:
sActionFileName = " & request("s_company") & "&Formlist_Page=" & [red]cStr(iPage)[/red] &"#list"

Or alternatively, pull the value from the QueryString like this:
sActionFileName = " & request("s_company") & "&Formlist_Page=" & [red]request("Formlist_Page")[/red] &"#list"
 
I get no value for Formlist_Page in the querystring for either an insert or an update.

Both have the desired effect on the database but still getting the CLng error.
 
when do you get the clng error i'm not getting that, what did you do to get that
 
Yeah the update goes thru but there is no value in Formlist_Page when going back to page 1.
 
The same code appears on page1. Look for this:

Code:
'-------------------------------
' Process page scroller
'-------------------------------
  iPage = GetParam("Formlist_Page")
  if IsEmpty(iPage) then iPage = 1 else iPage = CLng(iPage)
 
Of course changing this to get rid of the CLng() error wont fix the underlying problem of the missing QueryString value.
 
zxcdf5je fixed your problem look at previous post for directions
 
Find this:


'-------------------------------
' Execute SQL statement
'-------------------------------
if len(slistErr) > 0 then Exit Sub
on error resume next
if bExecSQL then
cn.execute sSQL
end if
slistErr = ProcessError
on error goto 0
if len(slistErr) > 0 then Exit Sub
cn.Close
Set cn = Nothing
response.redirect sActionFileName



Write out the value of sActionFileName and see.
 
When I try to update a record, I still get:
Code:
Microsoft VBScript runtime error '800a000d' 
Type mismatch: 'CLng' 

/samples/listGrid.asp, line 340

The URL that I am redirected to after an update is:
Code:
[URL unfurl="true"]http://www.jliwebsites.com/samples/listGrid.asp?s_company=&Formlist_Page=1#list[/URL]

Now there [red]IS[/red] a valid value for Formlist_Page but this error is still happening... I guess line 340 is not the line that has CLng(iPage)
 
this is line 340

if IsEmpty(iPage) then iPage = 1 else iPage = CLng(iPage)

then problem is this part #list

because you can't clng this 1#list , so if we remove the #list part eerything should work fine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top