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.

    EMW, Nov 6, 2005
    1. Advertisements

  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">

    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
    Karl Seguin, Nov 7, 2005
    1. Advertisements

  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") =

    Eliyahu Goldin, Nov 7, 2005
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.