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