Results 1 to 4 of 4

Thread: change image on imagebutton

  1. #1

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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;

  3. #3

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: change image on imagebutton

    I have this part of code:
    VB Code:
    1. Dim sb As New System.Text.StringBuilder
    2.                 sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
    3.                 sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
    4.                 sb.Append("var answer = confirm('Save mutations?'); ")
    5.                 sb.Append("if (answer) { ")
    6.                 sb.Append(Me.Page.GetPostBackEventReference(Me.btnSave))
    7.                 sb.Append("; ")
    8.                 sb.Append("this.ImageUrl=""images\apply.JPG""; ")
    9.                 'sb.Append("this.hidden = true; ")
    10.                 sb.Append("this.disabled = true; }")
    11.                 sb.Append(" else {")
    12.                 sb.Append(" return false; }")
    13.                 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?

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: change image on imagebutton

    sb.Append("this.ImageUrl=""images\apply.JPG""; ")

    That's not even valid javascript. Why are you doing a GetPostbackeventReference?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width