Link Button Question (II)

Discussion in 'ASP .Net' started by Zach, May 18, 2012.

  1. Zach

    Zach Guest

    In ASP I can put text on a linkbutton in the aspx file.
    But I don't seem to be able to change the back colour
    after having clicked the link button. Is there a way to
    do this?

    Zach
     
    Zach, May 18, 2012
    #1
    1. Advertisements

  2. Zach

    Arne Vajhøj Guest

    CSS

    http://www.w3schools.com/css/css_link.asp

    has an example.

    Arne
     
    Arne Vajhøj, May 19, 2012
    #2
    1. Advertisements

  3. Zach

    Zach Guest

    Yes that is interesting. However, using style sheets I cannot get it to
    work.
    I have tried different formats.

    Zach.
     
    Zach, May 19, 2012
    #3
  4. Zach

    Zach Guest

    Arne,

    I have discovered how it works.
    Once you have in the style sheet e.g.

    ..LinkButton1
    {
    // some code
    }

    you can add

    ..LinkButton1:hover{
    background-color: yellow;

    }

    Then the link button will light up yellow as you hover it
    which is funky. But what you cannot do is keep the linkbutton
    yellow till you klick another linkbutton so the user will know
    what he/she has been referred to e.g. in a neighbouring textbox.
    That would of course need something other than "hover". But
    I don't see that option available.

    If you create one of several click functions and in one
    function you want to give the linkbutton background
    colour yellow, till you click another linkbutton, then
    there is no way of doing that - that I could find.

    Zach.
     
    Zach, May 19, 2012
    #4
  5. Change the control's BackColor property in the control's onClick event.

    Assuming the markup as

    <asp:LinkButton ID="LinkButton1" runat="server"
    onclick="LinkButton1_Click">LinkButton</asp:LinkButton>

    the color will be changed by using this event handler

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
    LinkButton1.BackColor = System.Drawing.Color.Red;
    }

    regards
    A.G.
     
    Registered User, May 19, 2012
    #5
  6. Zach

    Zach Guest

    Hi,

    Excellent!
    Thank you.

    Zach.
     
    Zach, May 19, 2012
    #6
  7. Zach

    Arne Vajhøj Guest

    The traditional web way is that links has one style
    before click and one style after first click.

    CSS can do that.

    CSS can not do what you describe. Which seems to be that
    only latest clicked link should have a special style so
    that a clicked link fall back to start style when the
    next link is clicked.

    Arne
     
    Arne Vajhøj, May 20, 2012
    #7
  8. Zach

    Arne Vajhøj Guest

    It does what you want.

    But I don't link the solution.

    There will be styles in both CSS and code behind. That
    could become rather messy.

    You could use the variant where you just set the
    CssClass property in the code behind and leave
    the actual styles to the CSS.

    Arne
     
    Arne Vajhøj, May 20, 2012
    #8
  9. Zach

    Zach Guest

    Arne,

    Yes it might be considered messy.
    But it does work OK.
    How else to do it though.

    Zach.
     
    Zach, May 20, 2012
    #9
  10. Zach

    Arne Vajhøj Guest

    Set the CssClass property i the code behind and
    let the CSS define what it actually does.

    Arne
     
    Arne Vajhøj, May 20, 2012
    #10
    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.
Similar Threads
There are no similar threads yet.
Loading...