Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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:

Never trouble another for what you can do for yourself.
Posted

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

Posted

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 :)

Never trouble another for what you can do for yourself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...