Auto Click Button after some delay using JavaScript in ASP.Net

t01779393200
 
on Aug 28, 2021 01:31 AM
Sample_889547.zip
384 Views

page load then wait 3 sec then auto button1 click

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect("/");
}

 

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="auto clik" />

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 28, 2021 03:17 AM

Hi t01779393200,

Refer below code.

HTML

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="auto clik" />
<script type="text/javascript">
    window.onload = function () {
        setTimeout(function () {
            document.getElementById('<%=Button1.ClientID %>').click();
        }, 5000);
    };
</script>

Code

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Redirect("/");
}