Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > asp code does not render for first record in looped recordset

Reply
Thread Tools

asp code does not render for first record in looped recordset

 
 
Daniel Crichton
Guest
Posts: n/a
 
      07-23-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote on Wed, 23 Jul 2008 07:45:54 -0700 (PDT):

> This is the code to narrow in on:


> onmouseover="showBigImage( 'imagescript.asp?path=<%=
> images.Fields.Item( "url_img" ).Value %>&width=250','<%=
> images.Fields.Item( "url_img" ).Value %>','<
> %=(images.Fields.Item("alt_img").Value)%>' )">


> This '<%=(images.Fields.Item("alt_img").Value)%>' portion of the code
> is what is not rendering for the initial image of the recordset



Silly question, but are you sure the value of alt_img for that row in the
database actually has a value?

And another thing to consider (which shouldn't affect this though) is that
you should ensure that there is no way to get an apostrophe into your
database, or if you do allow it that you ensure that you escape it (ie store
it as \') or else you risk breaking the javascript handling in the client
(or even worse potentially allowing cross-site scripting).

--
Dan


 
Reply With Quote
 
 
 
 
haft@canchair.com
Guest
Posts: n/a
 
      07-23-2008
CONNECTION SCRIPT PAGE CODE:

<%
' FileName="Connection_ado_conn_string.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="true"
' Catalog=""
' Schema=""
Dim MM_Custom4_STRING
MM_Custom4_STRING = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &
Server.MapPath("/access_db/Custom4.mdb")
%>

PAGE CODE OF DISCUSSION:

<!--#include file="Connections/Custom4.asp" -->
<%
Dim images
Dim images_numRows


Set images = Server.CreateObject("ADODB.Recordset")
images.ActiveConnection = MM_Custom4_STRING
images.Source = "SELECT url_img, alt_img, sort_img_prd, productfam,
productid_img, ColourAtt1, ColourAtt2, ColourAtt3, subfam, desc_fam,
title_fam FROM images WHERE productid_img = " +
Replace(images__MMColParam, "'", "''") + ""
If Request.QueryString("ProductFamily") <>"" Then
images.Source = images.Source & " OR
ProductFam="&Request.QueryString("ProductFamily")& ""
End If
images.Source = images.Source & " AND ColourAtt1 IS NULL AND
ColourAtt2 IS NULL AND ColourAtt3 IS NULL ORDER BY sort_img_prd DESC"
'images.Source = "SELECT url_img, alt_img, sort_img_prd, productfam,
productid_img, ColourAtt1, ColourAtt2, ColourAtt3, sub, desc_fam,
title_fam FROM images WHERE productid_img = " +
Replace(images__MMColParam, "'", "''") + " OR (ProductFam=1) ORDER BY
sort_img_prd DESC"
images.CursorType = 0
images.CursorLocation = 2
images.LockType = 1
images.Open()

images_numRows = 0

%>


"images" is an access select query comprised of all the fields listed
in the above recordset select statement.
"alt_img" is a Memo Data Type (The General values listed are:
Required: No, Allow Zero Length: No, Indexed: Yes (Duplicates OK),
Unicode Compression: Yes, IME Mode: No Control, IME Sentence Mode:
None)

And no, there are no apostrophes in the alt_img values to be tripping
the javascript code and yes, the alt_img field does contain a value. I
have tested this page on 3 different products and the same occurs for
each as to verify that this is not a product-specific error.
 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      07-23-2008
(E-Mail Removed) wrote:
> CONNECTION SCRIPT PAGE CODE:
>
> <%
> ' FileName="Connection_ado_conn_string.htm"
> ' Type="ADO"
> ' DesigntimeType="ADO"
> ' HTTP="true"
> ' Catalog=""
> ' Schema=""
> Dim MM_Custom4_STRING
> MM_Custom4_STRING = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &
> Server.MapPath("/access_db/Custom4.mdb")
> %>


OK, you should not be using the obsolete ODBC driver when there is a
native OLE DB Jet provider; the connection string should be

"Provider=Microsoft.Jet.OLEDB.4.0;" & _
data source = " & Server.MapPath("/access_db/Custom4.mdb")

>

<snip>
> Set images = Server.CreateObject("ADODB.Recordset")
> images.ActiveConnection = MM_Custom4_STRING


Nothing to do with your problem, but this is poor coding practice. You
should use an explicit connection object to make sure connection pooling
can work properly:

dim cn:set cn = createobject)"adodb.connection")
cn.open MM_Custom4_STRING

> images.Source = "SELECT url_img, alt_img, sort_img_prd, productfam,
> productid_img, ColourAtt1, ColourAtt2, ColourAtt3, subfam, desc_fam,
> title_fam FROM images WHERE productid_img = " +
> Replace(images__MMColParam, "'", "''") + ""


Again, nothing to do with your problem, but the + signs should be &
symbols. A better practice would be to assign this string to a variable
which will make debugging easier:

dim sSQL
sSQL = "SELECT ... "

> If Request.QueryString("ProductFamily") <>"" Then
> images.Source = images.Source & " OR
> ProductFam="&Request.QueryString("ProductFamily")& ""
> End If
> images.Source = images.Source & " AND ColourAtt1 IS NULL AND
> ColourAtt2 IS NULL AND ColourAtt3 IS NULL ORDER BY sort_img_prd DESC"
> 'images.Source = "SELECT url_img, alt_img, sort_img_prd, productfam,
> productid_img, ColourAtt1, ColourAtt2, ColourAtt3, sub, desc_fam,
> title_fam FROM images WHERE productid_img = " +
> Replace(images__MMColParam, "'", "''") + " OR (ProductFam=1) ORDER BY
> sort_img_prd DESC"


Same comment: don't assign this stuff directly to the Source property.

> images.CursorType = 0
> images.CursorLocation = 2
> images.LockType = 1


Hmmm ... going to a lot of trouble to set default properties ...

> images.Open()


Here is how it should look:
images.Open sSQL, cn,,,1
Actually, you could boil all the above down to:

dim sSQL
sSQL = "SELECT ... "
dim cn:set cn = createobject)"adodb.connection")
cn.open MM_Custom4_STRING
set images=cn.execute(sSQL,,1)

Make sure you close both the recordset and the connection when you are
finished using them.

>
> images_numRows = 0
>
> %>
>
>
> "images" is an access select query

(excuse the nitpick)
Er, no. "images" is a recordset object opened using a select statement
run against a Jet database.
The select query is the string that hopefully you will change the code
to assign to sSQL.

> comprised of all the fields listed
> in the above recordset select statement.
> "alt_img" is a Memo Data Type (The General values listed are:
> Required: No,


So nulls are allowed ... You said you tested whether the first record
had a value in alt_img but failed to say how you tested this.

> Allow Zero Length: No, Indexed: Yes (Duplicates OK),
> Unicode Compression: Yes, IME Mode: No Control, IME Sentence Mode:
> None)
>


I see no problems besides the poor coding practices I highlighted. Try
the changes i suggested, and if they don't help, I doubt this is an "asp
problem". It is likely to be a data problem with the data in the
database. One thing:
do you have the same problem if you change sort_img_prd DESC to
sort_img_prd ASC?
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
Old Pedant
Guest
Posts: n/a
 
      07-23-2008
Not sure why some posters thought this had anything to do with JS and nothing
to do with recordset.

I certainly don't know anything other than a recordset object that uses the
code pattern
[name].Field.Item('...fieldname...").Value

Now, it's also true that DumbWeaver is plunking in way too much code there.

The expression
<% = images.Fields.Item( "url_img" ).Value %>
is 100% equivalent to the easier-to-write, easier-to-read, and MEASURABLY
FASTER
<%=images("url_img")%>
And I do recommend that you switch to that.

***************

Having said all that.

I see no reason at all in any of your code that the first description
doesn't show up in the output. (And it's clearly nothing to do with
apostrophes...a VIEW-->>SOURCE of the HTML of your page shows that there is
NOTHING WHATSOEVER there.)

So I have to question your actual database. Are you 100% *SURE* that you
actually *HAVE* any text in the
alt_img
field for that given
url_img
value????

In other words, go into your Access database (using Access, not using ASP,
not using DumbWaster) and find the record where
url_img
is
images/portable_stage.jpg
Then, *IN THAT SAME RECORD*, find what the value of
alt_img
is. I am personally betting that the value is blank. And so you are
getting exactly what you should.

**********************

I do note that your code isn't *REALLY* doing what it *SHOULD* be doing.

You said to look at the UR
http://www.canchair.com/new_web_prod...ctFamilySub=10

I did. I also looked at
ProductID=111
and
ProductFamilySub=12
and tried various other combinations. And I still got the same images, no
matter what.

So given all that, maybe it's not surprising that the DB doesn't have a
value in one field when you think it should.

*************************************

By the not so insignifcant by...your HTML code is ILLEGAL. It is rendering
thus:

<a href= "javascript:;" class="small_img" >
<td height=36 valign="middle" class="small_img"
onmouseover="showBigImage(
'imagescript.asp?path=images/portable_stage.jpg&width=250','images/portable_stage.jpg',''
)"><img src="imagescript.asp?path=images/portable_stage.jpg&width=36"
border="0" alt="" > </td>
</a>
But it's illegal to have <A>...</A> tags *OUTSIDE* of the <TD>...</TD> tags.

As it turns out, MSIE is sloppy and allows this. Don't count on other
browser to do so.

Of course, the bigger question is a simple one: What's the point of the <A>
tag there, in the first place????? It is doing EXACTLY NOTHING. I would
string recommend removing the <A> and </A> tags.

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      07-23-2008
Old Pedant wrote:
> Not sure why some posters thought this had anything to do with JS and
> nothing
> to do with recordset.
>


If you're asking why I missed it, the answer is simple: I do not expect to
see a recordset object named "images". Even if I had, I still had not seen
enough to decide where the problem was.


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Old Pedant
Guest
Posts: n/a
 
      07-24-2008
"Bob Barrows [MVP]" wrote:
> If you're asking why I missed it, the answer is simple: I do not expect to
> see a recordset object named "images".


I thought you weren't only one that missed that. I thought a couple of
other posters did.

But no matter. It's obvious you haven't had to work with the junk that DW
produces as much as I have. I recognized its patterns (even its BigImage
stuff) right off. I think, all in all, you should consider yourself very
fortunate. <grin/>

[I admit, I tend to go overboard, ragging on DreamWeaver, but sheesh!
They've been producing the same crappy code since 1998 or so. I'm sure
nobody is doing any active work on improving it, today, but you'd think that
SOMEBODY would have changed SOME of their idiocies back in 2000 through 2002
or so.]




Even if I had, I still had not seen
> enough to decide where the problem was.
>
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
>
>

 
Reply With Quote
 
Dooza
Guest
Posts: n/a
 
      07-24-2008
Old Pedant wrote:
> [I admit, I tend to go overboard, ragging on DreamWeaver, but sheesh!
> They've been producing the same crappy code since 1998 or so. I'm sure
> nobody is doing any active work on improving it, today, but you'd think that
> SOMEBODY would have changed SOME of their idiocies back in 2000 through 2002
> or so.]


Dreamweaver CS4 is in public beta, all they did was break the UI and
improve the CSS abilities. The server side code hasn't changed since DW8
where they introduced paramatised commands to help prevent SQL injection.

Dreamweaver users have been screaming out for improved server side code
support for many years. Due to the poor support of server side code, and
regular browsing of this newsgroup, I have improved my asp/vbscript
coding abilities, but still use Dreamweaver to "design" my web applications.

Steve
 
Reply With Quote
 
Old Pedant
Guest
Posts: n/a
 
      07-24-2008


"Dooza" wrote:
> Dreamweaver users have been screaming out for improved server side code
> support for many years. Due to the poor support of server side code, and
> regular browsing of this newsgroup, I have improved my asp/vbscript
> coding abilities, but still use Dreamweaver to "design" my web applications.


A smart person, you are. The dozen or so people who I've taken "in hand" do
pretty much the same thing: Do the HTML design with DW but then do all the
ASP coding (or at least much of it) by hand.

If nothing else, the amount of "kruft" that you get rid of that way makes
your pages run twice as fast.

[I don't do much HTML "design", and what I do is done with notepad or VS
2003, even when coding in ASP. I'm lucky in that I get to be the "backend"
to designers' front-ends.]


 
Reply With Quote
 
Dooza
Guest
Posts: n/a
 
      07-25-2008
Old Pedant wrote:
>
> "Dooza" wrote:
>> Dreamweaver users have been screaming out for improved server side code
>> support for many years. Due to the poor support of server side code, and
>> regular browsing of this newsgroup, I have improved my asp/vbscript
>> coding abilities, but still use Dreamweaver to "design" my web applications.

>
> A smart person, you are. The dozen or so people who I've taken "in hand" do
> pretty much the same thing: Do the HTML design with DW but then do all the
> ASP coding (or at least much of it) by hand.


I recently found out that Stored Procedures can output more than 1
recordset, and that you can easily step to the next one in ASP/VBScript.
This is something Dreamweaver will never do, yet it can save you
making several trips to the database. Since I do everything I can with
Stored Procedures to keep my database as secure as possible, this is a
great trick to use.

> If nothing else, the amount of "kruft" that you get rid of that way makes
> your pages run twice as fast.
>
> [I don't do much HTML "design", and what I do is done with notepad or VS
> 2003, even when coding in ASP. I'm lucky in that I get to be the "backend"
> to designers' front-ends.]


I have always been a visual designer. One of my early jobs in tech
support was for HoTMetaL Pro. The only way to support a package like
that was to learn what it was trying to do. I soon found it was bloody
awful at making good code! So I bought a book, Web Master in a Nutshell,
and started to dabble. When I found Dreamweaver 2 it appeared to make
better code, and let me be more creative whilst still letting me take
control of the code... haven't looked back since then, and have made a
nice living from it so far, always learning on the way.

Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript function call does not contain rendered asp code for firstrecord of recordset haft@canchair.com Javascript 0 07-24-2008 10:37 PM
I'm lazy: how do I make the first databound record not display/chop off the first element from SqlDataSource ASP .Net 7 06-28-2006 10:24 AM
Self looped Port physically connected, how could this be? Victor Cappuccio Cisco 2 07-26-2004 11:48 PM
Page.Render do not render complete page Lau Lei Cheong ASP .Net 1 05-15-2004 04:10 AM
RecordSet.Move or RecordSet.AbsolutePosition?? Hung Huynh ASP General 8 09-24-2003 11:07 AM



Advertisments