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

t01779393200
 
on Aug 28, 2021 01:09 AM
Sample_135117.zip
415 Views

page load, then wait 5 second,  then auto click HyperLink1.NavigateUrl go to site

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

 

HyperLink1.Text = "asp net good site";
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 28, 2021 03:20 AM
on Sep 13, 2021 12:55 AM

Hi t01779393200,

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