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

Display Image 1

Status
Not open for further replies.

A1Pat

IS-IT--Management
Jun 7, 2004
454
US
Hi all,

I'm new at ASP.NET and working on a page that previously created with ASP to display a called image, and I'm having problem having the image display because ASP.NET doesn't allow <%%> within its code. Here is my code:

<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"<html xmlns="<head><title>Striker Sample</title>
</head>
<body bgcolor="#ffffff">
<%
dim img
img = trim(request.QueryString("img"))
%>
<form runat="server">
<asp:image runat="server" ImageUrl="images/<%=img%>.jpg" />
</form>

<hr /><p align="right"><a href="#" onclick="self.close();return false;"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Close Window</font></a></p>
</body></html>

I know my code is not yet complete nor created correctly. Please help me learn more about ASP.NET.
 
Nevermind... I got it works now.

Thanks anyway!
 
If you could please share how you did it for us other ASP.NET beginners. Thanks.
 
Setting the ImageURL property in the code is best practice, FYI.

Good luck iwth your ASP.Netting :)
 
The reason you are having problems is because you are trying to use classic ASP methods to acheive the results you want. ASP.NET is trying to get developers to seperate logic from content and as such, the code you write should be moved to the code behind file. To acheive the above in this fashions you would have this in your aspx page:
Code:
<asp:image runat="server" id="myImage" />
and this in your code behind file:
Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        myImage.ImageURL = "images/" & Request.QueryString("img") & ".jpg"
    End Sub
This will also alow you to debug your project much easier as well as being easier to maintain.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Yes, my code is exactly the way ca8msm described.

Thank you all for paying attention to my post.
 
However, a little different... I post it anyway...

<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"<html xmlns="<head><title>Striker Sample</title>
<script runat="server">
Sub Page_Load
dImg.ImageURL = "images/" & trim(request.QueryString("img")) & ".jpg"
End Sub
</script>
</head>
<body bgcolor="#ffffff">

<form runat="server">
<asp:image ID="dImg" runat="server" />
</form>

<hr /><p align="right"><a href="#" onclick="self.close();return false;"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Close Window</font></a></p>
</body></html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top