How to create a fading label in JQuery / ASP.NET after a button press

后端 未结 4 626
面向向阳花
面向向阳花 2021-01-22 13:59

I think that this should be pretty easy but I\'m not quite sure how to wire things up.

I have a page on which the user can define a query. When done, the user enters a

相关标签:
4条回答
  • 2021-01-22 14:43

    Here's a low-tech technique that keeps all the script in your page template: add a $(document).ready() function to the page that executes conditionally based on a page-level variable, like this ...

    // In your button's click handler, set this.UserHasClicked to true
    var userHasClicked = '<%= this.UserHasClicked %>' == 'True';
    $(document).ready(function() {
        if(userHasClicked) {
            $(labelSelector).delay(2000).fadeOut(1000);
        }
    });
    
    0 讨论(0)
  • 2021-01-22 14:45

    Something like this...

    var buttonFade = function() {
      $('#my .label .selector').fadeOut(2000);
    }
    setTimeout(buttonFade, 2000);
    

    If you post some of your markup, I could also take a stab at putting the setTimeout() into a function triggered when the label appears.

    0 讨论(0)
  • 2021-01-22 14:54

    Start the asp label text as empty.

    <asp:Label id="myLabel" runat="server"></asp:Label>
    

    Then you can fade out the label every page load and set the text of the asp label after hitting the button.

    Protected Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
      myLabel.Text = "You hit the button"
    End Sub
    
        $(document).ready(function() {
            $('#myLabel').fadeOut(3000, function() {
                $(this).html(""); //reset the label after fadeout
            });
        });
    
    0 讨论(0)
  • 2021-01-22 15:02

    Call ClientScriptManager.RegisterClientScriptBlock

    0 讨论(0)
提交回复
热议问题