Mondeo Posted April 17, 2007 Posted April 17, 2007 I have an imagebutton control, i'm setting its src property using javascript as its part of an image swap type routine. But then when its .net click event fires and need to know the filename of the actual image - i.e. the src attribute. However Imagebutton.ImageURL is nothing. Is there anyway I can get at the underlying image src filename? Thanks Quote
MrPaul Posted April 17, 2007 Posted April 17, 2007 Use a hidden form field The src attribute of an image is not posted back to the server. If you want to post it back I suggest you add a hidden input field to your form, and modify your Javascript to change the value of this field when the image URL is changed. When the form is posted back to the server you can query this hidden form field to retrieve the image URL. Good luck :cool: Quote Never trouble another for what you can do for yourself.
Mondeo Posted April 18, 2007 Author Posted April 18, 2007 Thanks for that, i'm getting an error message though. This is my script (the bold is the line i've added) function ChangeSource(imageID) { document.getElementById('imgMain').src = document.getElementById(imageID).src document.myform.picid.value = document.getElementById('imgMain').src; } The error is document.myform.picid is null or not an object My form declaration is <form runat=server name="myform"> And the field is <input type="hidden" id="picid"> Did I miss something? Thanks Quote
Leaders snarfblam Posted April 18, 2007 Leaders Posted April 18, 2007 Should you be setting the name attribute of the input? Quote [sIGPIC]e[/sIGPIC]
MrPaul Posted April 21, 2007 Posted April 21, 2007 getElementById Strange that you use the more widely supported getElementById but then on the next line you use the DOM-style which is less reliable in my experience. Try this: var imgID = document.getElementById(imageID); document.getElementById('imgMain').src = imgID.src; document.getElementById('picid').value = imgID.src; As marble_eater mentioned, make sure your hidden field has both a name and an id attribute. Good luck :) Quote Never trouble another for what you can do for yourself.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.