Rollover asp.net Button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oriane

    Rollover asp.net Button

    Hi there,

    I would like to handle a "rollover" <asp:Buttonin the code behind with C#
    with this kind of code:

    Button btn = Page.FindContro l("Button" + numWidget) as
    Button;
    btn.Attributes["onmouseove r"] = "document.a ll." +
    btn.ClientID + ".src = '/Images/blue.gif'";

    This code works for ImageButton...b ut not for Button (it does nothing).

    My goal is to change the background image.

    Best regards

  • Nathan Sokalski

    #2
    Re: Rollover asp.net Button

    It doesn't work for the Button control because the html input tag doesn't
    have a src attribute. But can I also ask why you are using a Button control
    when you want to assign it a *.gif file? However, if all you are looking to
    do is add a rollover feature to the Button that changes the background
    color, you may want to take a look at the AddRolloverBack groundColor
    function I have written that is available on my website at:



    Here is the simple code for the function if you want it separately from the
    other rollover functions I have written:

    Public Shared Sub AddRolloverBack groundColor(ByV al ctrl As
    System.Web.UI.W ebControls.WebC ontrol, ByVal rollover As
    System.Drawing. Color, ByVal initial As System.Drawing. Color)
    'Adds the background color rollover feature to a WebControl
    ctrl.BackColor = initial
    ctrl.Attributes .Add("onmouseov er",
    String.Format(" this.style.back groundColor='{0 }';",
    System.Drawing. ColorTranslator .ToHtml(rollove r)))
    ctrl.Attributes .Add("onmouseou t",
    String.Format(" this.style.back groundColor='{0 }';",
    System.Drawing. ColorTranslator .ToHtml(initial )))
    End Sub

    As you can see, my code is in VB.NET, but you can obviously convert it into
    C# without much trouble. Good Luck!
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


    "Oriane" <oriane@noemail .noemailwrote in message
    news:%23TK7YqxI JHA.508@TK2MSFT NGP05.phx.gbl.. .
    Hi there,
    >
    I would like to handle a "rollover" <asp:Buttonin the code behind with
    C# with this kind of code:
    >
    Button btn = Page.FindContro l("Button" + numWidget) as
    Button;
    btn.Attributes["onmouseove r"] = "document.a ll." +
    btn.ClientID + ".src = '/Images/blue.gif'";
    >
    This code works for ImageButton...b ut not for Button (it does nothing).
    >
    My goal is to change the background image.
    >
    Best regards

    Comment

    • Steven Cheng

      #3
      RE: Rollover asp.net Button

      Hi Oriane,

      The ImageButton and Button differs on their underlying html representation.
      You can view the html source of the asp.net page to verify that.

      I agree with Nathan that you can try using javascript to change the
      style.backgroun dColor or style.backgroun dImage attribute to acheive the
      same goal.






      Sincerely,

      Steven Cheng

      Microsoft MSDN Online Support Lead


      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      http://msdn.microsoft.com/en-us/subs...#notifications.
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.

      --------------------
      >From: "Oriane" <oriane@noemail .noemail>
      >Subject: Rollover asp.net Button
      >Date: Tue, 30 Sep 2008 18:35:06 +0200
      >
      >Hi there,
      >
      >I would like to handle a "rollover" <asp:Buttonin the code behind with
      C#
      >with this kind of code:
      >
      Button btn = Page.FindContro l("Button" + numWidget) as
      >Button;
      btn.Attributes["onmouseove r"] = "document.a ll." +
      >btn.ClientID + ".src = '/Images/blue.gif'";
      >
      >This code works for ImageButton...b ut not for Button (it does nothing).
      >
      >My goal is to change the background image.
      >
      >Best regards
      >
      >

      Comment

      • Oriane

        #4
        Re: Rollover asp.net Button

        Thanks for your answer

        Comment

        Working...