开发者

How to show/hide gif image when button click in asp.net

开发者 https://www.devze.com 2022-12-12 14:32 出处:网络
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.

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>

    &开发者_StackOverflow社区lt;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.


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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号