Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-04-14
8
Medium Priority
?
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 25

Expert Comment

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

Expert Comment

by:Christian de Bellefeuille
ID: 24136807
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
ID: 24136901
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:prashantagarw10
ID: 24137375
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
 
LVL 10

Expert Comment

by:Christian de Bellefeuille
ID: 24137409
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
ID: 24137547
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:
Christian de Bellefeuille earned 2000 total points
ID: 24137596
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
ID: 24137734
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

604 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