Advertisement

06.24.2008 at 11:21AM PDT, ID: 23512025
[x]
Attachment Details

String Values getting reset in VB.Net on ASP.Net 2.0 page

Asked by KaiserGuy in Microsoft Visual Basic.Net, Active Server Pages (ASP), .NET Framework 2.0

Tags: VB.NET, ASP.NET 2.0, FireFox 3 Beta, www.bibletruthpublishers.com/sbk

Why am I losing string values that I add to a 2 dimensional String array when I click on another date in a Calendar control? I am able to add strings during the Page_Load event and it works temporarily what I try later in the "butCustomAddEntry_Click" event but then when I click on another date in the calendar, the array seems to be reset to only the values in the Page_Load event. It seems like it is redimensioned every time a date is selected.

I am very new to ASP.Net 2.0. (Probably kinda obvious)Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
Partial Class Default2
    Inherits System.Web.UI.Page
    Dim holidays(12, 31) As String
 
    Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs)
        Dim d As CalendarDay
        Dim c As TableCell
 
        d = e.Day
        c = e.Cell
 
        If d.IsOtherMonth Then
            c.Controls.Clear()
        Else
            Try
                Dim Hol As String
                Hol = holidays(d.Date.Month, d.Date.Day)
 
                If Hol <> "" Then
                    c.Controls.Add(New LiteralControl("<br>" + Hol))
                End If
            Catch exc As Exception
                Response.Write(exc.ToString())
            End Try
        End If
    End Sub
 
    Sub Date_Selected(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar1.SelectionChanged
        If pnlCustomEntry.Visible = False Then
            pnlCustomEntry.Visible = True
        End If
        Label1.Text = "Selected date is: " + Calendar1.SelectedDate.ToShortDateString
        Label2.Text = Calendar1.SelectedDate.ToShortDateString
        Label3.Text = holidays(Calendar1.SelectedDate.Date.Month, Calendar1.SelectedDate.Date.Day)
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim temp As Object = "New Year's Day"
        holidays(1, 1) = temp
        holidays(1, 26) = "Australia Day"
        holidays(2, 2) = "Groundhog Day"
        holidays(2, 14) = "Valentine's Day"
        holidays(3, 17) = "St. Patrick's Day"
        holidays(4, 1) = "April Fool's Day"
        holidays(5, 1) = "May Day"
        holidays(6, 15) = "My Birthday"
        holidays(7, 15) = "My Anniversary"
        holidays(8, 15) = "My Mother's Birthday"
        holidays(9, 24) = "Autumnal Equinox"
        holidays(12, 26) = "Boxing Day"
        ' this line sets the calendar to start on January of next year
        Calendar1.VisibleDate = New Date(Now.Year + 1, 1, 1)
    End Sub
 
    Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles Calendar1.VisibleMonthChanged
        pnlCustomEntry.Visible = False
        'This portion keeps the calendar restricted to next year
        If Calendar1.VisibleDate.Year = Now.Year Then
            Calendar1.VisibleDate = New Date(Now.Year + 1, Calendar1.VisibleDate.Month, Calendar1.VisibleDate.Day)
        End If
    End Sub
 
    Protected Sub butCustomAddEntry_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butAddCustomEntry.Click
        holidays(Calendar1.SelectedDate.Date.Month, Calendar1.SelectedDate.Date.Day) = txtCustomEntry.Text()
    End Sub
End Class
Attachments:
 
The aspx page that runs the VB.NET code in my snippet
 
 
Loading Advertisement...
 
[+][-]06.24.2008 at 11:33AM PDT, ID: 21858783

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.24.2008 at 11:33AM PDT, ID: 21858784

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.24.2008 at 11:34AM PDT, ID: 21858803

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.24.2008 at 12:33PM PDT, ID: 21859503

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 06:41PM PDT, ID: 21861997

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 08:06PM PDT, ID: 21862412

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 09:48PM PDT, ID: 21862728

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, Active Server Pages (ASP), .NET Framework 2.0
Tags: VB.NET, ASP.NET 2.0, FireFox 3 Beta, www.bibletruthpublishers.com/sbk
Sign Up Now!
Solution Provided By: KaiserGuy
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628