Private
_imageFolderPath As
String = "~/images1"
Public
Property ImageFolderPath()
As String
Get
Return _imageFolderPath
End Get
Set(ByVal
Value As String)
_imageFolderPath = value
End Set
End
Property
Private
Sub Page_Load()
Dim imageToDisplay
As String =
GetRandomImage()
imgRandom.ImageUrl = Path.Combine(_imageFolderPath,
imageToDisplay)
lblRandom.Text = imageToDisplay
End Sub
Private
Function GetRandomImage()
As String
Dim rnd
As New
Random()
Dim images()
As String =
Directory.GetFiles(MapPath("~/images1"),
"*.JPG")
Dim imageToDisplay
As String =
images(rnd.Next(images.Length))
Return
Path.GetFileName(imageToDisplay)
End Function
</script>
<asp:Image
id="imgRandom"
Width="300px"
Runat="server"
/>
<br
/>
<asp:Label
id="lblRandom"
Runat="server"
/>
Default.aspx File Code
<%@
Page Language="VB"
CodeFile="Default.aspx.vb"
Inherits="_Default"%>
<%@
Register TagPrefix="user"
TagName="PropertyRandomImage"
Src="~/PropertyRandomImage.ascx"
%>
<!DOCTYPE
html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
runat="server">
<title></title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<user:PropertyRandomImage
ID="PropertyRandomImage1"
ImageFolderPath="~/images1"
Runat="server"
/>
</div>
</form>
</body>
</html>
Default2.aspx File Code
<%@
Page Language="VB"
AutoEventWireup="false"
CodeFile="Default2.aspx.vb"
Inherits="Default2"
%>
<%@
Register TagPrefix="user"
TagName="PropertyRandomImage"
Src="~/PropertyRandomImage.ascx"
%>
<!DOCTYPE
html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script
runat="server">
Protected
Sub Page_Load(ByVal
sender As Object,
ByVal e As
EventArgs)
PropertyRandomImage1.ImageFolderPath =
"~/images2"
End Sub
</script>
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
runat="server">
<title></title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
<user:PropertyRandomImage
ID="PropertyRandomImage1"
Runat="server"
/>
</div>
</form>
</body>
</html>
Note: Continue in next part.
HAVE A GREAT CODING!