imagebutton to set imageurl of image via javascripthttp://forums.asp.net/t/1800643.aspx/1?imagebutton+to+set+imageurl+of+image+via+javascriptMon, 07 May 2012 07:50:37 -040018006434967736http://forums.asp.net/p/1800643/4967736.aspx/1?imagebutton+to+set+imageurl+of+image+via+javascriptimagebutton to set imageurl of image via javascript <p>Hi,</p> <p>I'm creating a page where at the top there is a panel filled with small pictures on which the user can click.<br> When clicked I want to see the picture in a larger size below this panel.</p> <p>The small pictures are imagebuttons and I was thinking of using the OnClientClick command to set the url of the image control below.</p> <p>I use this code:</p> <p>btPhoto.OnClientClick = &quot;&lt;script&gt;document.getElement.By.Id['imPhoto'].src = &quot;&quot;&quot; &#43; fl.Substring(fl.IndexOf(&quot;photos\&quot;)) &#43; &quot;&quot;&quot;;&lt;/script&gt;&quot;</p> <p></p> <p>Obviously it is not working.</p> <p>fl has the string of the location of the image.<br> How can I set the images url via the OnClientClick command?</p> <p>rg,<br> Eric</p> <p><br> &nbsp;</p> 2012-05-06T15:21:09-04:004967767http://forums.asp.net/p/1800643/4967767.aspx/1?Re+imagebutton+to+set+imageurl+of+image+via+javascriptRe: imagebutton to set imageurl of image via javascript <p>I have changed my code to:</p> <pre style="font-size:13px; background:white; color:black; font-family:Consolas">&nbsp;btPhoto.OnClientClick&nbsp;=&nbsp;<span style="color:#a31515">&quot;javascript:showpic('imPhoto','&quot;</span>&nbsp;&#43;&nbsp;fl.Substring(fl.IndexOf(<span style="color:#a31515">&quot;photos\&quot;</span>))&nbsp;&#43;&nbsp;<span style="color:#a31515">&quot;');&quot;</span></pre> <pre style="font-size:13px; background:white; color:black; font-family:Consolas"><span style="color:#a31515"></span>&nbsp;</pre> <p>And I have added this function to the aspx page:</p> <pre class="prettyprint">&lt;script type=&quot;text/javascript&quot;&gt; function showpic(objID, objSrc) { var bigpic = document.getElementById(objID); bigpic.src = objSrc; return false; } &lt;/script&gt;</pre> <p>The function is called, that I checked by replacing the first two lines with an alert.<br> But the above code is not working. The page, when shown in IE, gives errors, but they don't say anything usefull.</p> <p>Any solutions?</p> <p>rg,<br> Eric</p> 2012-05-06T16:11:19-04:004967807http://forums.asp.net/p/1800643/4967807.aspx/1?Re+imagebutton+to+set+imageurl+of+image+via+javascriptRe: imagebutton to set imageurl of image via javascript <p>Found the problem.</p> <p>First the \ in the link to the image must be a / otherwise it will be swapped to a . (dot)</p> <p>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.</p> <p>rg,<br> Eric</p> 2012-05-06T17:25:51-04:004968367http://forums.asp.net/p/1800643/4968367.aspx/1?Re+imagebutton+to+set+imageurl+of+image+via+javascriptRe: imagebutton to set imageurl of image via javascript <p>Hi,</p> <p>Try this-</p> <p><a href="http://forums.asp.net/p/1800740/4968251.aspx/1?Re&#43;Change&#43;Image&#43;source&#43;using&#43;javascript">http://forums.asp.net/p/1800740/4968251.aspx/1?Re&#43;Change&#43;Image&#43;source&#43;using&#43;javascript</a></p> 2012-05-07T06:46:29-04:004968528http://forums.asp.net/p/1800643/4968528.aspx/1?Re+imagebutton+to+set+imageurl+of+image+via+javascriptRe: imagebutton to set imageurl of image via javascript <p>thank you.</p> 2012-05-07T07:50:37-04:00