views:

1041

answers:

2

Hi, I have a asp page where i have a button.When i click on the button i should display a gif image.When the process is completed ,again the images has to be hidden.

Please find my below code behind

<head runat="server">
    <title>Untitled Page</title>

    <script type="text/javascript" language="javascript">

    </script>

</head>
<body>
    <form id="form1" runat="server">
        <div style="display: none" id="dvloader">
            <img src="Images/process_status.gif" /></div>
        <asp:Button ID="btnLoad" runat="server" Text="Load" OnClick="btnLoad_Click" />
    </form>
</body>

Please find the below code behind

 protected void btnLoad_Click(object sender, EventArgs e)
    {
       // Show the gif image
        System.Threading.Thread.Sleep(5000);
        // hide the gif image
    }

How can i achive this ?

Thanks.

+2  A: 

The method in your example is server-sided. What you want to do is on the client side and must be done in javascript therefore.

You could use the client-sided onclick-event to show the GIF after the button has been clicked. You can set the client-sided onclick-event somwhere in the Page-Load method for example:

btnLoad.Attributes.Add("onclick", "alert('JavaScript to show GIF goes here...');");

After the PostBack, the GIF will be hidden again automatically...

Vinz
its working but the gif image is not in motion,What would be the issue ?
Jebli
Hmm, this must be a browser dependent issue. If I remember correctly, IE stops animated GIFs as soon as a page-request is started. In fact, this question is exactly about that problem: http://stackoverflow.com/questions/1540079/animated-gif-does-not-animate-on-page-load-in-ie.I think this issue cannot be solved. Do you have the same effect with other browsers?
Vinz
A: 

You could actually apply the event to the element without using the inline event handler.

Using jquery you could say:

 $(document).ready(function() {

$('#btnLoad').click(function(){alert('JavaScript to show GIF goes here...');});


});

This assumes your button has an id of btnload.

matpol
but the image is not moving.Its like a static image.but in design mode its moving
Jebli