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

Swaping Image Location with ASP tags

Status
Not open for further replies.

PNeems

Programmer
May 17, 2008
19
0
0
US
I had written a page in html/js and set up a very simple function to swap the location of a picture between the main location and the thumbnail location.

function changewindow(filename)
{
document.mainwindow.src = filename;
}

<img src="Image/Front.JPG" name="mainwindow" height="300px" width="300px"/>

<a href="javascript:changewindow('Image/Front.JPG')">
<img border="0" src="Image/Front.JPG" width="75" height="75"></a>

I used this code to do the image swapping so when you click on the smaller image it changes its location to the mainwindow image name.

However, I am trying to make this page now based on server data so I am using asp:Image tags now so i can set the location in the page behind. The asp:Image tag has no name attribute, i tried replacing it with the ID and using the getelementID, but that didnt seem to work either. Does anyone know how i would do this?
Ahy help would be appreciated. Thanks!
 
you can add an attribute to any server control using
Code:
MyImage.Attributes.Add("name", "mainwindow");
getelementbyid probally did not work because server web controls produce auto-generated client ids.

if you want to use the client ids you need to pass MyControl.ClientID to the rendered page.
for example, your markup may look like this
Code:
<script>
function changewindow(filename)
{
   document.getElementById('<%#MyImage.ClientId%>').src = filename;
}
</script>
<asp:Image id="MyImage" runat="server" ... />

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
and next time post questions related to asp.net in forum855

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top