C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Display a RandomImage on Page Load using Sessions


Posted Date: 10 Jun 2008    Resource Type: Code Snippets    Category: VB.NET Syntax
Author: komaladeviMember Level: Gold    
Rating: Points: 7



First, we need to use System.IO to display the Random Images on Page Load,
if the browser is closed and the session ends, a new image will be chosen at random upon a new session start, and remain until the session ends, again.




Imports System.IO

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
chooseImage()
End Sub

Public Function chooseImage() As String
If Session("img") Is Nothing Then
Dim imgPath As String
Dim fileCount As Integer = Directory.GetFiles(Server.MapPath("/media/img/"), "*.*", SearchOption.TopDirectoryOnly).Length
fileCount = fileCount + 1
imgPath = "media/img/" & RandomNumber(1, fileCount) & ".jpg"
Session("img") = imgPath
Return imgPath
Else
Return Session("img").ToString()
End If
End Function

Private Function RandomNumber(ByVal min As Integer, ByVal max As Integer) As Integer
Dim random As New Random()
Return random.Next(min, max)
End Function
End Class




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: reading / writing Cookies in .net
Previous Resource: Getting text from Text file
Return to Discussion Resource Index
Post New Resource
Category: VB.NET Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use