asp Hyperlink button (C#) : Hyperlink « Asp Control « ASP.Net






asp Hyperlink button (C#)

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
    void Page_Load()
    {
        lnkRandom.NavigateUrl = GetRandomFile();
    }

    string GetRandomFile()
    {
        string[] files = Directory.GetFiles(MapPath(Request.ApplicationPath), "*.aspx");
        Random rnd = new Random();
        string rndFile = files[rnd.Next(files.Length)];
        return Path.GetFileName(rndFile);
    }
        
</script>
<html>
<head id="Head1" runat="server">
    <title>Show HyperLink</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    <asp:HyperLink
        id="lnkRandom"
        Text="Random Link"
        Runat="server" />
    
    </div>
    </form>
</body>
</html>

           
       








Related examples in the same category

1.Displaying a Graphic on a HyperLink Control (VB.net)
2.asp:HyperLink: border style and width (VB.net)
3.Hyperlink: command name and url (VB.net)
4.asp:HyperLink with NavigateURL (VB.net)
5.asp hyperlink: font, width and text (C#)