Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 13th, 2003, 12:46 PM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default href popup link database

Hi,

I want it to display the product information when a user clicks a link from a table. But, I havent got a clue about where to start.
I am displaying an alternate color table from what i assume is a recordset. please excuse my ignorance if this is straight forward as i only just started to attempt anything like this in the last week.

here is the code im using

show.asp

<html>
<head>
<body>
<%
dim Id
ID = Request.QueryString("ID")
%>
<script language="JavaScript">

function orderdetails(strProdID)
{
   newwind = window.open(("file.asp?ID=" + strProdID),"left=20, top=0, width=700 , height=550,toolbar=0, status=1, scrollbars=1,resizable=1");
}


</script>
</body>
 </head>

<h4 align=center>Please Click On Following Links</h4>

<div align="center">
  <center>

<TABLE border=1 cellPadding=1 cellSpacing=1 width="75%">

  <TR>
    <TD valign="middle" align="center">No</TD>
    <TD valign="middle" align="center">Model</TD>
    <TD valign="middle" align="center">type</TD> </center>
</div>


 <%
strDB= "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
        strDB = strDB & Server.MapPath("images.mdb")

                  set data = server.createobject("ADODB.RecordSet")
                  data.activeconnection = strDB
                  data.source = "SELECT * FROM try1"
                  data.PageSize = 5
                  'data.CacheSize = 5
                  data.CursorLocation = 3
                  data.open

                  If Len(Request("pagenum")) = 0 Then
                data.AbsolutePage = 1
            Else
                If CInt(Request("pagenum")) <= data.PageCount Then
                        data.AbsolutePage = Request("pagenum")
                    Else
                        data.AbsolutePage = 1
                End If
        End If
        Dim abspage, pagecnt
                Dim fldF, intRec
            abspage = data.AbsolutePage
            pagecnt = data.PageCount



                  For intRec=1 To data.PageSize

                   if data.EOF then

                   else

            Response.Write "<tr><td valign='middle' align='center'>"
            Response.Write data("Id") & "</td><td valign='middle' align='center'>"


 Response.Write "<a href=""file.asp?ID=" & data("Id") & """>"
          (this code open product in same win)


 Response.Write "<A HREF=""javascript:winOpen('file.asp?ID= data(Id)'), & data(Id) & "">"
       (and here is the code which i want to rectify)

            Response.Write data("File Name")
            Response.Write "</td><td valign='middle' align='center'>" & data("Model Type") & "</td></tr>"
            'Response.Write "</td><td valign='middle' align='center'>" & data("Content Type") & "</td></tr>"

            data.MoveNext

                       end if
                    next


                    data.close
                    set data = nothing %></tr></table>

           <% Response.Write "<div align=""center"">" & vbcrlf


                If abspage = 1 Then
                Response.Write "<span style=""color:silver;""><b>Previous Page</span>"

                Else
                Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?pagenum=" & abspage - 1 & """><b>Previous Page</a>"

                End If

                Response.Write "&nbsp;|&nbsp;"

                If abspage < pagecnt Then

                Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?pagenum=" & abspage + 1 & """><b>Next Page</a>"

                Else

                Response.Write "<span style=""color:silver;""><b>Next Page</span>"
                Response.Write "<br>" & "thanks for watching our product"
                End If



        %>
                  </html>




file.asp(which in link with show.asp)


<%
   ' -- file.asp --
   ' Retrieves binary files from the database

   Response.Buffer = True

   ' ID of the file to retrieve
   Dim ID
      ID = Request("ID")

   If Len(ID) < 1 Then
      ID = 7

   End If

   ' Connection String
   Dim connStr
      connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
         Server.MapPath("images.mdb")

   ' Recordset Object
   Dim rs
      Set rs = Server.CreateObject("ADODB.Recordset")

      ' opening connection
      'rs.Open "select * from try"
      rs.Open "select [File Data],[Content Type] from try1 where ID = " & _
        ID, connStr, 2, 4

      If Not rs.EOF Then

         Response.ContentType = rs("Content Type")
         Response.BinaryWrite rs("File Data")

      End If


      rs.Close
      Set rs = Nothing
%>



<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>

<P>&nbsp;</P>

</BODY>
</HTML>

thanks



 
Old December 13th, 2003, 04:52 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

If it's about this line:

Response.Write "<A HREF=""javascript:winOpen('file.asp?ID= data(Id)'), & data(Id) & "">"


then you'll need to separate the literal string (a href etc) from the variables / values retrieved from the recordset:

Response.Write "<a href=""javascript:winOpen('file.asp?ID=" & data(Id) & "')" & """>"

This will pass 'file.asp?ID=SomeValue to a JavaScript function called winOpen (which, BTW, is not defined in the page). Is this what you're after? If not, can you please be more specific?

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 14th, 2003, 03:58 AM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok i have to be more specific

i got database which has images,store in binary files
and open database in show.asp file which got href link of
image so when user click on link,image should open in new
window


 
Old December 14th, 2003, 08:15 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Well, to make this work correctly, you'll need to define the JavaScript function: winOpen as I indicated in my previous post.

This function could look pretty much like orderdetails in that it expects a parameter and then uses window.open to open a new window.
Instead of passing it a strProdID, you are passing it the entire URL.

Something like this:

function winOpen(strURL)
{
newwind = window.open(strURL, null, "height=200,width=400,status=yes,toolbar=no,menuba r=no,location=no");
}

This will open a new window when the function is called.

Does the page that writes out the image work?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 14th, 2003, 11:51 AM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes
everything get work properly even it display images
if i put following code
Response.Write "<a href=""file.asp?ID=" & data("Id") & """>"

but it display on same page
even i try your suggestion but it still didnt work it gives me
error

ADODB.Fields error '800a0cc1'

ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.



 
Old December 14th, 2003, 01:22 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It would be really helpful if you'd specify where you're getting the error, with what code, on what page, on what line number, etc. It's impossible for me to see from here what you're doing, so I can't tell what the error is. You need to help us help you.

Anyway, the error indicates you're referencing a field that does not exist in the database, or is not retrieved with the SELECT statement.

If you post the code for both pages, I'll take a look at it and see if I can clean things up a bit.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 15th, 2003, 03:10 AM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have already posted my both the file
show.asp
file.asp
which is still on my first post
pls chk


 
Old December 15th, 2003, 03:34 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

And what have you done with my other suggestions? I showed you how to fix the <a href> and how to add the JavaScript function to open the new window. Either you can't be sure it doesn't work because you haven't tried it yet, or the source must be different by now, don't you agree?

I can only show you how it it's done; I am not going to write the entire solution for you.

So, change the <a> tag, try to add the winOpen function with the code I showed you. See if it works then and if not, post the source of the pages as they are by then and I'll take a look.
Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 15th, 2003, 05:48 AM
Registered User
 
Join Date: Dec 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

those r the changes which i had done


<html>
<head>
<body>
<%
dim Id
ID = Request.QueryString("ID")
%>
<script language="javascript">
function winOpen(strURL)
{
newwind = window.open(strURL, null, "height=200,width=400,status=yes,toolbar=no,menuba r=no,location=no");
}

</script>


</script>
</body>
 </head>

<h4 align=center>Please Click On Following Links</h4>

<div align="center">
  <center>

<TABLE border=1 cellPadding=1 cellSpacing=1 width="75%">

  <TR>
    <TD valign="middle" align="center">No</TD>
    <TD valign="middle" align="center">Model</TD>
    <TD valign="middle" align="center">type</TD> </center>
</div>


 <%
strDB= "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
        strDB = strDB & Server.MapPath("images.mdb")

                  set data = server.createobject("ADODB.RecordSet")
                  data.activeconnection = strDB
                  data.source = "SELECT * FROM try1"
                  data.PageSize = 5
                  'data.CacheSize = 5
                  data.CursorLocation = 3
                  data.open

                  If Len(Request("pagenum")) = 0 Then
                data.AbsolutePage = 1
            Else
                If CInt(Request("pagenum")) <= data.PageCount Then
                        data.AbsolutePage = Request("pagenum")
                    Else
                        data.AbsolutePage = 1
                End If
        End If
        Dim abspage, pagecnt
                Dim fldF, intRec
            abspage = data.AbsolutePage
            pagecnt = data.PageCount



                  For intRec=1 To data.PageSize

                   if data.EOF then

                   else

            Response.Write "<tr><td valign='middle' align='center'>"
            Response.Write data("Id") & "</td><td valign='middle' align='center'>"
           'Response.Write "<a href=""file.asp?ID=" & data("Id") & """>"

(here is the code which i had change as you suggest)

                Response.Write "<a href=""javascript:winOpen('file.asp?ID=" & data(Id) & "')" & data(Id)& """>"




            Response.Write data("File Name")
            Response.Write "</td><td valign='middle' align='center'>" & data("Model Type") & "</td></tr>"
            'Response.Write "</td><td valign='middle' align='center'>" & data("Content Type") & "</td></tr>"

            data.MoveNext

                       end if
                    next


                    data.close
                    set data = nothing %></tr></table>


        %>
                  </html>



 
Old December 15th, 2003, 01:12 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The line with the biggest problem is the one that writes out the JavaScript link and the ID. Here's how it should be:

Response.Write "<a href=""javascript:winOpen('file.asp?ID=" & data("Id") & "')"">" & data("Id")& "</a>" & vbCrLf

This will write a link to the ID from the recordset. When you click the link, winOpen will fire and a new window will be opened.

Also, you need to do this:

data("id")

instead of

data(id)

You're referencing a column name by passing in a string.

I think this should fix some of your problems, so you should be able to continue......

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving XML thru href link using XSLT kaukabhishek XSLT 16 June 25th, 2008 07:16 PM
setting combox box value to href in <link> bhairraju CSS Cascading Style Sheets 2 March 23rd, 2007 01:58 PM
XML value in HRef link aware XSLT 3 January 8th, 2007 08:52 AM
How to Avoid PopUp Windows when link to a file? Dragonist HTML Code Clinic 3 July 29th, 2004 08:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.