Thursday, May 5, 2011

Time-dependent Hyperlink (VB.NET)

1. Open up Visual Studio 2010.
2. Create web-form and name it default.aspx
3. Drag Hyperlink-element from toolbox and place on a page between body-tags.
Give ID="HyperLinkTime"
Save the form.
4. Open up code-behind page Default.aspx.vb and place some code on Page_Load
'Time-dependent hyperlink
Dim DateStart As Date = "3/1/2011 12:00AM"
Dim DateEnd As Date = "6/1/2011 12:00PM"
Dim DateNow As Date = System.DateTime.Now

Dim result1 As Integer = DateTime.Compare(DateNow, DateStart)
Dim result2 As Integer = DateTime.Compare(DateNow, DateEnd)

If (result1 > 0) And (result2 < 0) Then
HyperLinkTime.NavigateUrl = "http://www.yahoo.com"
HyperLinkTime.Text = "Yahoo.com"
Else
' Do nothing
End If
Save and test.
Hyperlink "Yahoo.com" will show up only between 3/1/2011 and 6/1/2011. The dates can be changed any time.

No comments:

Post a Comment