Auto Click Hyperlink after some delay in ASP.Net

t01779393200
 
on Aug 27, 2021 06:55 AM
678 Views

i want page load then 5 sec delay then auto Click HyperLink1.NavigateUrl  this possible?

<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>

 

protected void Page_Load(object sender, EventArgs e)
{
    HyperLink1.Text = "asp net good site";
    HyperLink1.NavigateUrl = "https://www.aspforums.net/Users/t01779393200/Threads";
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 29, 2021 01:24 AM
on Aug 29, 2021 02:24 AM

Hi t01779393200,

The correct way to delay the Hyperlink click is to use JavaScript setTimeout function.

Refer below sample code.

HTML

<asp:HyperLink ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>
<script type="text/javascript">
    window.onload = function () {
        setTimeout(function () {
            document.getElementById('<%=HyperLink1.ClientID %>').click();
        }, 5000);
    };
</script>

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    HyperLink1.Text = "asp net good site";
    HyperLink1.NavigateUrl = "https://www.aspsnippets.com/";
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    HyperLink1.Text = "asp net good site"
    HyperLink1.NavigateUrl = "https://www.aspsnippets.com/"
End Sub

Screenshot