How to change the background image dynamicly?

Discussion in 'ASP .Net' started by EMW, Nov 6, 2005.

  1. EMW

    EMW Guest

    For my page I have created two backgrounds.
    On startup is uses image1 and when the user clicks on a linkbutton it should
    use image2.
    Here is were problem is.
    I cannot find how to do this.
    I can set the background to image1 and then open the page in IE, but how can
    I swap it to image 2 programmaticly?

    There is no style property and als the backgroundimage property isn't there.

    I'm using ASP2.NET and visual basic.

    rg.
    Eric
    EMW, Nov 6, 2005
    #1
    1. Advertising

  2. EMW

    Karl Seguin Guest

    There are a couple ways, but probably the one I like the most is to simply
    add a runat="Server" to the body tag

    <body id="body" runat="server">
    ....
    </body>


    then declare it in your codebehind,

    protected body as HtmlGenericControl

    and you can then do thigns like

    body.Styles.Add("background-image", "url('image2.gif'");

    or something

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/
    http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!



    "EMW" <> wrote in message
    news:436e576d$0$723$...
    > For my page I have created two backgrounds.
    > On startup is uses image1 and when the user clicks on a linkbutton it
    > should use image2.
    > Here is were problem is.
    > I cannot find how to do this.
    > I can set the background to image1 and then open the page in IE, but how
    > can I swap it to image 2 programmaticly?
    >
    > There is no style property and als the backgroundimage property isn't
    > there.
    >
    > I'm using ASP2.NET and visual basic.
    >
    > rg.
    > Eric
    >
    >
    Karl Seguin, Nov 7, 2005
    #2
    1. Advertising

  3. Eric,

    This can be easily done with a client-side onclick event. You can set it up
    in the server-side code:

    myLinkButton.Attributes("onclick") =
    "window.document.body.background='image2.gif'"

    Eliyahu

    "EMW" <> wrote in message
    news:436e576d$0$723$...
    > For my page I have created two backgrounds.
    > On startup is uses image1 and when the user clicks on a linkbutton it

    should
    > use image2.
    > Here is were problem is.
    > I cannot find how to do this.
    > I can set the background to image1 and then open the page in IE, but how

    can
    > I swap it to image 2 programmaticly?
    >
    > There is no style property and als the backgroundimage property isn't

    there.
    >
    > I'm using ASP2.NET and visual basic.
    >
    > rg.
    > Eric
    >
    >
    Eliyahu Goldin, Nov 7, 2005
    #3
    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. Henke
    Replies:
    0
    Views:
    1,499
    Henke
    Feb 26, 2004
  2. jc
    Replies:
    3
    Views:
    1,704
  3. jc
    Replies:
    1
    Views:
    1,339
    Neredbojias
    Mar 19, 2008
  4. Replies:
    1
    Views:
    349
    GArlington
    Jul 1, 2008
  5. Leoa
    Replies:
    4
    Views:
    113
Loading...

Share This Page