change image on imagebutton
Hi all,
I've got the following problem. I have an imagebutton. When clicking the imagebutton, a question must be answerd with ok or cancel (javascript). Cancel does nothing, Ok fires some actions. What I want is this: when hitting the ok button when asked, the imagebutton should be unclickable (solved that part myself), but the image on the button should also be changed by another image. Does anyone know how to do that part, or some sample code?
I guess the image should be made available to the user when loading the page in the browser, although it is not visible by default. But I don't know how...
Thanx in advance,
JMvV
Re: change image on imagebutton
Aren't you going about this the long way?
To start with, you can have a hidden field (with runat=server) on your form. The confirm() javascript function returns the value which gets written to the hidden field. You can get this confirm() working on the imagebutton by using .Attributes.Add() in the codebehind, for the imagebutton. Which means that you can also specify javascript in there to change the image of the imagebutton.
You would change the image using
Code:
document[imgname].src=newimageurl;
Re: change image on imagebutton
I have this part of code:
VB Code:
Dim sb As New System.Text.StringBuilder
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
sb.Append("var answer = confirm('Save mutations?'); ")
sb.Append("if (answer) { ")
sb.Append(Me.Page.GetPostBackEventReference(Me.btnSave))
sb.Append("; ")
sb.Append("this.ImageUrl=""images\apply.JPG""; ")
'sb.Append("this.hidden = true; ")
sb.Append("this.disabled = true; }")
sb.Append(" else {")
sb.Append(" return false; }")
btnSave.Attributes.Add("onclick", sb.ToString())
The only thing that is not happening is changing the image (this.ImageUrl=and_so_on). How could I achieve this goal?
Re: change image on imagebutton
sb.Append("this.ImageUrl=""images\apply.JPG""; ")
That's not even valid javascript. Why are you doing a GetPostbackeventReference?