Swapping Image Url

Discussion in 'ASP .Net' started by Guadala Harry, Aug 13, 2004.

  1. In an aspx page I have declared an Image control:
    <asp:Image id="myImage" runat="server"></asp:Image>

    In the code-behind I populate it's ImageURL property, like this:
    myImage.ImageUrl = "some.gif";

    Then, in client-side JavaScript, the user can cause the image to be
    replaced, like this:
    document.all("myImage").src = "other.gif";

    Here's the problem: on postback, the image control's .ImageUrl property
    still contains "some.gif" and not "other.gif" as I am needing.

    What do I need to do to receive - during postback - the value set in the
    client by the JavaScript?

    Thanks!
    Guadala Harry, Aug 13, 2004
    #1
    1. Advertising

  2. After postback, the value of ImageUrl is coming from the control's ViewState.

    One solution would be to set the value of a hidden field when you set the
    image's src attribute. The value of the hidden field will get posted back
    correctly.

    "Guadala Harry" wrote:

    > In an aspx page I have declared an Image control:
    > <asp:Image id="myImage" runat="server"></asp:Image>
    >
    > In the code-behind I populate it's ImageURL property, like this:
    > myImage.ImageUrl = "some.gif";
    >
    > Then, in client-side JavaScript, the user can cause the image to be
    > replaced, like this:
    > document.all("myImage").src = "other.gif";
    >
    > Here's the problem: on postback, the image control's .ImageUrl property
    > still contains "some.gif" and not "other.gif" as I am needing.
    >
    > What do I need to do to receive - during postback - the value set in the
    > client by the JavaScript?
    >
    > Thanks!
    >
    >
    >
    >
    =?Utf-8?B?QnJhZCBRdWlubg==?=, Aug 13, 2004
    #2
    1. Advertising

  3. Thanks - I thought about going the hidden field route - but was hoping for
    some solution that wouldn't require adding another field or control that
    needs synchronizing with the original Image control.

    Any other ideas?

    Thanks again...

    -G



    "Brad Quinn" <> wrote in message
    news:...
    > After postback, the value of ImageUrl is coming from the control's

    ViewState.
    >
    > One solution would be to set the value of a hidden field when you set the
    > image's src attribute. The value of the hidden field will get posted back
    > correctly.
    >
    > "Guadala Harry" wrote:
    >
    > > In an aspx page I have declared an Image control:
    > > <asp:Image id="myImage" runat="server"></asp:Image>
    > >
    > > In the code-behind I populate it's ImageURL property, like this:
    > > myImage.ImageUrl = "some.gif";
    > >
    > > Then, in client-side JavaScript, the user can cause the image to be
    > > replaced, like this:
    > > document.all("myImage").src = "other.gif";
    > >
    > > Here's the problem: on postback, the image control's .ImageUrl property
    > > still contains "some.gif" and not "other.gif" as I am needing.
    > >
    > > What do I need to do to receive - during postback - the value set in the
    > > client by the JavaScript?
    > >
    > > Thanks!
    > >
    > >
    > >
    > >
    Guadala Harry, Aug 13, 2004
    #3
  4. Guadala Harry

    Toby Mathews Guest

    Can you make the code in your codebehind only execute the first time it
    executes? i.e.

    if (!Page.IsPostback)
    myImage.ImageUrl = "some.gif";

    Toby Mathews

    "Guadala Harry" <> wrote in message
    news:%...
    > Thanks - I thought about going the hidden field route - but was hoping for
    > some solution that wouldn't require adding another field or control that
    > needs synchronizing with the original Image control.
    >
    > Any other ideas?
    >
    > Thanks again...
    >
    > -G
    >
    >
    >
    > "Brad Quinn" <> wrote in message
    > news:...
    > > After postback, the value of ImageUrl is coming from the control's

    > ViewState.
    > >
    > > One solution would be to set the value of a hidden field when you set

    the
    > > image's src attribute. The value of the hidden field will get posted

    back
    > > correctly.
    > >
    > > "Guadala Harry" wrote:
    > >
    > > > In an aspx page I have declared an Image control:
    > > > <asp:Image id="myImage" runat="server"></asp:Image>
    > > >
    > > > In the code-behind I populate it's ImageURL property, like this:
    > > > myImage.ImageUrl = "some.gif";
    > > >
    > > > Then, in client-side JavaScript, the user can cause the image to be
    > > > replaced, like this:
    > > > document.all("myImage").src = "other.gif";
    > > >
    > > > Here's the problem: on postback, the image control's .ImageUrl

    property
    > > > still contains "some.gif" and not "other.gif" as I am needing.
    > > >
    > > > What do I need to do to receive - during postback - the value set in

    the
    > > > client by the JavaScript?
    > > >
    > > > Thanks!
    > > >
    > > >
    > > >
    > > >

    >
    >
    Toby Mathews, Aug 13, 2004
    #4
  5. That's not really relevant to the problem - it would be IF there was an
    issue with postback processing walking on the value set in the client - but
    issue is that the value set in the client code is never making it to the
    server (unless I explicitly stuff the value into a hidden field - which I
    don't want to do unless I really must).

    Thanks anyway.


    "Toby Mathews" <> wrote in message
    news:cfhs1q$87n$...
    > Can you make the code in your codebehind only execute the first time it
    > executes? i.e.
    >
    > if (!Page.IsPostback)
    > myImage.ImageUrl = "some.gif";
    >
    > Toby Mathews
    >
    > "Guadala Harry" <> wrote in message
    > news:%...
    > > Thanks - I thought about going the hidden field route - but was hoping

    for
    > > some solution that wouldn't require adding another field or control that
    > > needs synchronizing with the original Image control.
    > >
    > > Any other ideas?
    > >
    > > Thanks again...
    > >
    > > -G
    > >
    > >
    > >
    > > "Brad Quinn" <> wrote in message
    > > news:...
    > > > After postback, the value of ImageUrl is coming from the control's

    > > ViewState.
    > > >
    > > > One solution would be to set the value of a hidden field when you set

    > the
    > > > image's src attribute. The value of the hidden field will get posted

    > back
    > > > correctly.
    > > >
    > > > "Guadala Harry" wrote:
    > > >
    > > > > In an aspx page I have declared an Image control:
    > > > > <asp:Image id="myImage" runat="server"></asp:Image>
    > > > >
    > > > > In the code-behind I populate it's ImageURL property, like this:
    > > > > myImage.ImageUrl = "some.gif";
    > > > >
    > > > > Then, in client-side JavaScript, the user can cause the image to be
    > > > > replaced, like this:
    > > > > document.all("myImage").src = "other.gif";
    > > > >
    > > > > Here's the problem: on postback, the image control's .ImageUrl

    > property
    > > > > still contains "some.gif" and not "other.gif" as I am needing.
    > > > >
    > > > > What do I need to do to receive - during postback - the value set in

    > the
    > > > > client by the JavaScript?
    > > > >
    > > > > Thanks!
    > > > >
    > > > >
    > > > >
    > > > >

    > >
    > >

    >
    >
    Guadala Harry, Aug 13, 2004
    #5
  6. Guadala Harry

    Toby Mathews Guest

    Harry,

    Sorry, I didn't read your message properly first time round. I'm not sure
    how else you could achieve what you want to do other than how you decribe.
    Good luck,

    Toby

    "Guadala Harry" <> wrote in message
    news:%...
    > That's not really relevant to the problem - it would be IF there was an
    > issue with postback processing walking on the value set in the client -

    but
    > issue is that the value set in the client code is never making it to the
    > server (unless I explicitly stuff the value into a hidden field - which I
    > don't want to do unless I really must).
    >
    > Thanks anyway.
    >
    >
    > "Toby Mathews" <> wrote in message
    > news:cfhs1q$87n$...
    > > Can you make the code in your codebehind only execute the first time it
    > > executes? i.e.
    > >
    > > if (!Page.IsPostback)
    > > myImage.ImageUrl = "some.gif";
    > >
    > > Toby Mathews
    > >
    > > "Guadala Harry" <> wrote in message
    > > news:%...
    > > > Thanks - I thought about going the hidden field route - but was hoping

    > for
    > > > some solution that wouldn't require adding another field or control

    that
    > > > needs synchronizing with the original Image control.
    > > >
    > > > Any other ideas?
    > > >
    > > > Thanks again...
    > > >
    > > > -G
    > > >
    > > >
    > > >
    > > > "Brad Quinn" <> wrote in message
    > > > news:...
    > > > > After postback, the value of ImageUrl is coming from the control's
    > > > ViewState.
    > > > >
    > > > > One solution would be to set the value of a hidden field when you

    set
    > > the
    > > > > image's src attribute. The value of the hidden field will get

    posted
    > > back
    > > > > correctly.
    > > > >
    > > > > "Guadala Harry" wrote:
    > > > >
    > > > > > In an aspx page I have declared an Image control:
    > > > > > <asp:Image id="myImage" runat="server"></asp:Image>
    > > > > >
    > > > > > In the code-behind I populate it's ImageURL property, like this:
    > > > > > myImage.ImageUrl = "some.gif";
    > > > > >
    > > > > > Then, in client-side JavaScript, the user can cause the image to

    be
    > > > > > replaced, like this:
    > > > > > document.all("myImage").src = "other.gif";
    > > > > >
    > > > > > Here's the problem: on postback, the image control's .ImageUrl

    > > property
    > > > > > still contains "some.gif" and not "other.gif" as I am needing.
    > > > > >
    > > > > > What do I need to do to receive - during postback - the value set

    in
    > > the
    > > > > > client by the JavaScript?
    > > > > >
    > > > > > Thanks!
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Toby Mathews, Aug 13, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard

    image swapping problem

    Richard, Sep 6, 2003, in forum: HTML
    Replies:
    1
    Views:
    348
    Richard
    Sep 6, 2003
  2. Jeanne D

    Image swapping/Rollovers

    Jeanne D, Oct 23, 2005, in forum: HTML
    Replies:
    6
    Views:
    456
    dorayme
    Oct 25, 2005
  3. Jeff
    Replies:
    2
    Views:
    335
    Jesse Houwing
    Apr 19, 2009
  4. Jeff
    Replies:
    2
    Views:
    1,386
    William Niver
    Apr 29, 2009
  5. Hubbers
    Replies:
    0
    Views:
    106
    Hubbers
    Jun 1, 2006
Loading...

Share This Page