[RESOLVED] [2005] displaying images via javascript and httphandler
as always right after i post i figure it out
ok my turn to ask the question:p
i once/do have this code in a classic asp site see it in action here
HTML Code:
....
<div style="margin-top: 15px; font-weight: bold; font-size: 12pt; float: left; margin-left: 5px;
color: black">
<img alt="BOTTLE RUN XTREME" src="img/home/xtreme_logo2.gif" />
<br />
<br />
<br />
We're the Ultimate Trials Dealer!
<br />
Everything for Motorcycle and Bicycle Trials.
<br />
If it's Xtreme - we carry it!
</div>
<%call ShowFeaturedMotorcycle()%>
<div style="clear: both">
....
Code:
<%
sub ShowFeaturedMotorcycle()
dim sql
'Make sure the recordset object is closed
if rs.state = 1 then
rs.close
end if
'Make sure the connection object is open
if cn.state <> 1 then
cn.open application("CnnStr")
end if
if cn.state = 1 then
sql = "SELECT motorcycle_inv.id, motorcycle_inv.model, motorcycle_inv.build_year, motorcycle_inv.price, motorcycle_brands.brand " & _
"FROM motorcycle_brands INNER JOIN motorcycle_inv ON motorcycle_brands.id = motorcycle_inv.make_id " & _
"WHERE motorcycle_inv.featured = 1"
rs.open sql, cn
if rs.state = 1 then
if not (rs.bof and rs.eof) then
dim pic_sql
dim pic_rs
set pic_rs = server.CreateObject("ADODB.Recordset")
pic_sql = "SELECT id FROM motorcycle_pics WHERE motorinv_id = " & rs("id")
pic_rs.open pic_sql, cn
if not (pic_rs.bof and pic_rs.eof) then
%>
<script language="JavaScript" type="text/javascript">
var imgFeature = new Array();
<%
dim i
i = 0
do until pic_rs.eof
%>
imgFeature[<%=i%>] = new Image();
imgFeature[<%=i%>].src = "asp/display-motopic-blob.asp?pic_id=<%=pic_rs("id")%>&width=250";
<%
i = i + 1
pic_rs.movenext
loop
%>
var IntervalID;
IntervalID = setInterval("ShowFeatureBike(0)", 0);
function ShowFeatureBike(index){
clearInterval(IntervalID);
if(index == imgFeature.length)
index = 0;
document.getElementById("MotorFeature").src = imgFeature[index].src;
index++;
IntervalID = setInterval("ShowFeatureBike(" + index + ")", 3000);
}
</script>
<div style="padding-right: 10px; float: right">
<img id="MotorFeature" src="" /></div>
<%
pic_rs.close
set pic_rs = nothing
%>
<div style="clear: both">
</div>
<div style="float: right; width: 250px">
<div style="font-weight: bold; font-size: 12pt; color: black">
Featured Motorcycle</div>
<div style="font-size: 10pt; color: black">
<%=rs("build_year") & " " & rs("model") & " " & rs("brand") & "<span style=""font-weight:bold;""> $" & rs("price") & "</span>"%>
</div>
</div>
<%
end if
end if
end if
end if
'Make sure the recordset object is closed
if rs.state = 1 then
rs.close
end if
'Make sure the connection object is open
if cn.state <> 1 then
cn.open application("CnnStr")
end if
end sub
%>
now i'm converting it to a ASP.NET 2.0 site i'd like to perform the same thing but with ASP.NET framework so here's what i have
this is in a webcontrol
Code:
<%=CreateJavascriptCode()%>
this is in the code-behind
Code:
Protected Function CreateJavascriptCode() As String
With New StringBuilder
.Append("<script language=""JavaScript"" type=""text/javascript"">")
.AppendLine()
.Append("var imgFeature = new Array();")
.AppendLine()
Dim sz As String() = BrxHelper.GetFeatureMotorcyclePicIds(FeaturedMotorcycle(DbConstants.COL_PUBLICCYCLEINVENTORYINVENTORYID))
For i As Integer = 0 To sz.Length - 1
.AppendFormat("imgFeature[{0}] = new Image();", i)
.AppendLine()
.AppendFormat("imgFeature[{0}].src = ""../ImageHandler.ashx?PictureId={1}&Size=S"";", i, sz(i))
.AppendLine()
Next
.AppendLine()
.Append("var IntervalID;")
.AppendLine()
.Append("IntervalID = setInterval(""ShowFeatureBike(0)"", 3000);")
.AppendLine()
.Append("function ShowFeatureBike(index){")
.AppendLine()
.Append("clearInterval(IntervalID);")
.AppendLine()
.Append("if(index == imgFeature.length){")
.AppendLine()
.Append("index = 0;}")
.AppendLine()
.Append("document.getElementById(""motorcycleFeaturePics"").src = imgFeature[index].src;")
.AppendLine()
.Append("index++;")
.AppendLine()
.Append("IntervalID = setInterval(""ShowFeatureBike("" + index + "")"", 8000);")
.AppendLine()
.Append("}")
.AppendLine()
.Append("</script>")
Return .ToString
End With
End Function
i can see that the javascript it working because i had placed an alert in the ShowFeatureBike function to see what the value of the document.getElementById(""motorcycleFeaturePics"").src was... however it does not return or display an image... i know the handler works because i use it for displaying images elsewhere and i've tested it... so hopefully someone might have an idea on how i can do this... :afrog: