I'm creating a page where at the top there is a panel filled with small pictures on which the user can click.
When clicked I want to see the picture in a larger size below this panel.
The small pictures are imagebuttons and I was thinking of using the OnClientClick command to set the url of the image control below.
<script type="text/javascript">
function showpic(objID, objSrc) {
var bigpic = document.getElementById(objID);
bigpic.src = objSrc;
return false;
}
</script>
The function is called, that I checked by replacing the first two lines with an alert.
But the above code is not working. The page, when shown in IE, gives errors, but they don't say anything usefull.
First the \ in the link to the image must be a / otherwise it will be swapped to a . (dot)
Then I found out, the function is working fine, but the page refreshes after the imagebutton click, changing the image url to empty as it was before the click event.
eric_W
Member
36 Points
92 Posts
imagebutton to set imageurl of image via javascript
May 06, 2012 03:21 PM|LINK
Hi,
I'm creating a page where at the top there is a panel filled with small pictures on which the user can click.
When clicked I want to see the picture in a larger size below this panel.
The small pictures are imagebuttons and I was thinking of using the OnClientClick command to set the url of the image control below.
I use this code:
btPhoto.OnClientClick = "<script>document.getElement.By.Id['imPhoto'].src = """ + fl.Substring(fl.IndexOf("photos\")) + """;</script>"
Obviously it is not working.
fl has the string of the location of the image.
How can I set the images url via the OnClientClick command?
rg,
Eric
eric_W
Member
36 Points
92 Posts
Re: imagebutton to set imageurl of image via javascript
May 06, 2012 04:11 PM|LINK
I have changed my code to:
And I have added this function to the aspx page:
<script type="text/javascript"> function showpic(objID, objSrc) { var bigpic = document.getElementById(objID); bigpic.src = objSrc; return false; } </script>The function is called, that I checked by replacing the first two lines with an alert.
But the above code is not working. The page, when shown in IE, gives errors, but they don't say anything usefull.
Any solutions?
rg,
Eric
eric_W
Member
36 Points
92 Posts
Re: imagebutton to set imageurl of image via javascript
May 06, 2012 05:25 PM|LINK
Found the problem.
First the \ in the link to the image must be a / otherwise it will be swapped to a . (dot)
Then I found out, the function is working fine, but the page refreshes after the imagebutton click, changing the image url to empty as it was before the click event.
rg,
Eric
asteranup
All-Star
30184 Points
4906 Posts
Re: imagebutton to set imageurl of image via javascript
May 07, 2012 06:46 AM|LINK
Hi,
Try this-
http://forums.asp.net/p/1800740/4968251.aspx/1?Re+Change+Image+source+using+javascript
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
eric_W
Member
36 Points
92 Posts
Re: imagebutton to set imageurl of image via javascript
May 07, 2012 07:50 AM|LINK
thank you.