Maes
Maes

Reputation: 164

Hide image automatically after 5 sec

I have an gif image in my project.When i click a button it should appear and after 5 sec it should dissapear from the screen. I tried using j query to do this.But i am not getting the output.Where i might gone wrong?

Below is my code i tried so far:

Jquery:

 $(function () {
        setTimeout(function () { $("#btnEmail").fadeOut(1500); }, 5000)
        $('#btnMail').click(function () {

            $('#btnEmail').show();
            setTimeout(function () { $("#btnEmail").fadeOut(1500); }, 5000)
        })
    })

HTML

<asp:LinkButton ID="btnEmail"  runat="server" onclick="btnMail_Click" Visible="false">
   <asp:Image ID="Image8" imageurl="~/Images/email_animation.gif" runat="server" class="box" /> </asp:LinkButton>

 <asp:LinkButton ID="btnMail"  runat="server" Text="Send" onclick="btnMail_Click"/>

btnMail_Click(Code Behind):

btnMail.Visible = false;
btnEmail.Visible = true;

Upvotes: 2

Views: 566

Answers (3)

Satpal
Satpal

Reputation: 133403

As You are using ASP.NET Controls generated ID of elements will be different.

You should use Control.ClientID Property.

Gets the control ID for HTML markup that is generated by ASP.NET.

Use

 $(function () {
    setTimeout(function () {
        $("#<%= btnEmail.ClientID %>").fadeOut(1500);
    }, 5000)
    $('#<%=btnMail.ClientID %>').click(function () {
        $('#<%=btnEmail.ClientID %>').show();
        setTimeout(function () {
            $("#<%=btnEmail.ClientID %>").fadeOut(1500);
        }, 5000)
    })
 })

Upvotes: 4

Hitesh Modha
Hitesh Modha

Reputation: 2790

You have to Give ClientID

$(document).ready(function(){
    $("#<%= btnEmail.ClientID %>").click(function () {

        $("#<%=Image8.ClientID %>").show();
        setTimeout(function () { $("#<%=Image8.ClientID %>").hide()}, 5000)
    })
});

Please ref: JSFiddle

Upvotes: 1

Gal Ziv
Gal Ziv

Reputation: 7372

there is a chance the clientId (the id the element get on browser) is different than the Id you mentioned. you should use ClientId property to set the id the control will receive on client.

  <asp:LinkButton ClientID="btnEmail"  runat="server" onclick="btnMail_Click" Visible="false">

ClientID on MSDN

Upvotes: 2

Related Questions