Solved

vb.net .aspx - Display different links on different months

Posted on 2009-04-14
8
267 Views
Last Modified: 2013-11-26
I have 12 sets of 4 page links I want to be displayed on a vb.net aspx page at different months of the year, so for example the page will display link1, link2, link3, link4 from 1st of january to the 31st of january and then link5, link6, link7, link8 from 1st of february to the 28th of february, etc, etc I would also like a text file to hold the links so that they can be easily changed at any time.

Thanks for the help!
0
Comment
Question by:Zoooink
8 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
Comment Utility
I don't understand for what do you want the text file. Explain it, please.
0
 
LVL 10

Expert Comment

by:cdebel
Comment Utility
The easiest way would be to use an XML file (its still text afterall), so it would be easier to load.
0
 
LVL 3

Author Comment

by:Zoooink
Comment Utility
XML would be fine, though the idea of the text file is so any administrative person without web development skills could change the links, without having to go in to code or anything like that, that's the reason, with an XML version, I would need an administretive page which allows a unskilled administrator to effectivley log in and change the links on the fly.
0
 
LVL 5

Expert Comment

by:prashantagarw10
Comment Utility
In this case  my suggestion would be to use a text file with 12 rows in it(1 for each month) and have 4 comma delimited values in it. Optionally, Each value can be a pair of Link text and Link URL both of which are further separated by a delimiter. The admin people will find this easier to maintain directly and you can easily write a program that reads the file as per this logic. However it must cater for invalid conditions e.g. if someone forgets to put a delimiter.
You should be very careful as this may hinder the user experience which is not good and it may take as long as 12 months to find a incorrect data in file.

Cheers!!
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 10

Expert Comment

by:cdebel
Comment Utility
Ok... here is what i would do.

Create a ASPX file with a calendar object in it like this:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="CalendarXML._Default" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
    </div>
    </form>
</body>
</html>

Then, you add the code bellow in the codebehind.  And don't forget to create your xml file.  I've included an exemple with links for the first 2 months in it.

I think we underestimate users too much.  Even a monkey can understand the pattern of the XML file
Imports System.Xml

Partial Public Class _Default

    Inherits System.Web.UI.Page
 

    Private aPathNav As System.Xml.XPath.XPathNavigator

    Private aPathDoc As System.Xml.XPath.XPathDocument

    Private aPathNodeIt As XPath.XPathNodeIterator

    Private aPathNode As XPath.XPathNavigator
 

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

        aPathDoc = New XPath.XPathDocument("LinksFile.xml")

        aPathNav = aPathDoc.CreateNavigator()
 

        If Not IsPostBack Then

            ShowLinks(Now().Month)

        End If

    End Sub
 

    Private Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles Calendar1.VisibleMonthChanged

        ShowLinks(e.NewDate.Month)

    End Sub
 

    Private Sub ShowLinks(ByVal nMonth As Integer)

        Try

            aPathNodeIt = aPathNav.Select("months/month_" & nMonth.ToString("00") & "/link")
 

            Page.Response.Write("Link lists: <BR>")

            For Each aPathNode In aPathNodeIt

                Page.Response.Write("<LI><A HREF=""" & aPathNode.Value() & """>" & aPathNode.Value() & "</A><BR>")

            Next

        Catch ex As Exception

            Page.Response.Write("No link define")

        End Try

    End Sub

End Class
 

-----------------------------------

XML File sample

<?xml version="1.0" encoding="utf-8" ?>

<months>

  <month_01>

    <link>http://www.microsoft.com</link>

    <link>http://support.microsoft.com</link>

    <link>http://msdn.microsoft.com</link>

    <link>http://technet.microsoft.com</link>

  </month_01>
 

  <month_02>

    <link>http://www.experts-exchange.com</link>

    <link>http://www.adobe.com</link>

    <link>http://www.download.com</link>

    <link>http://www.google.com</link>

  </month_02>

</months>

Open in new window

0
 
LVL 3

Author Comment

by:Zoooink
Comment Utility
Thanks forall the replies guys,

cdebel, you seem to be on the right track of what I am after, however, Iw as thinking of using something like an if statement perhaps...

if today.now() is greater than or equal to  01/01/09 and less than or equal to 01/31/09 then
link1
link2
link3
link4
elseif...

rathar than using the calander tool, basically I want the code in the page to handle all changes in the background, so whenever the end user browses to the page each month, they get a different set of links... What do you think?
0
 
LVL 10

Accepted Solution

by:
cdebel earned 500 total points
Comment Utility
Well, all what you have to change is to remove the calendar and use:
ShowLinks(Now().Month)

You don't need to check if its between day 1 and day 31, because you will fall into the leapyear trap, and if you compare it with dates litterally, what will happen in january 2010?  You will have to change your program code again!

So please, use Now().Month...
And remove the Calendar1 from the aspx and it will do the job
Imports System.Xml
 

Partial Public Class _Default

    Inherits System.Web.UI.Page
 

    Private aPathNav As System.Xml.XPath.XPathNavigator

    Private aPathDoc As System.Xml.XPath.XPathDocument

    Private aPathNodeIt As XPath.XPathNodeIterator

    Private aPathNode As XPath.XPathNavigator
 

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

        aPathDoc = New XPath.XPathDocument("LinksFile.xml")

        aPathNav = aPathDoc.CreateNavigator()
 

        ShowLinks(Now().Month)

    End Sub
 

    Private Sub ShowLinks(ByVal nMonth As Integer)

        Try

            aPathNodeIt = aPathNav.Select("months/month_" & nMonth.ToString("00") & "/link")
 

            Page.Response.Write("Link lists: <BR>")

            For Each aPathNode In aPathNodeIt

                Page.Response.Write("<LI><A HREF=""" & aPathNode.Value() & """>" & aPathNode.Value() & "</A><BR>")

            Next

        Catch ex As Exception

            Page.Response.Write("No link define")

        End Try

    End Sub

End Class

Open in new window

0
 
LVL 3

Author Comment

by:Zoooink
Comment Utility
Top notch cdebel!

I thought you might catch me on the literal thing! I did think about that after I'd submitted my post! lol

Thanks for the help!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now