I'm using an ArrayList to pass the values from the form to another page. This page has a bunch of Label boxes to display the information. When I set the value I get a "declaration expected" for the label1.text. Why am I getting this and how do I fix it?
thanks
grady
register2.aspx.vb Partial Class register_register2
Inherits System.Web.UI.Page
Dim myNewArrayList As ArrayList = Session("ddlArrayList")
Label1.Text=myNewArrayList(0)
label2.Text=myNewArrayList(1)
label3.Text=myNewArrayList(2)
label4.Text=myNewArrayList(3)
label5.Text=myNewArrayList(4)
label6.Text=myNewArrayList(5)
label7.Text=myNewArrayList(6)
label8.Text=myNewArrayList(7)
label9.Text=myNewArrayList(8)
label10.Text=myNewArrayList(9)
label11.Text=myNewArrayList(10)
label12.Text=myNewArrayList(11)
label13.Text=myNewArrayList(12)
label14.Text=myNewArrayList(13)
label15.Text=myNewArrayList(14)
label16.Text=myNewArrayList(15)
label17.Text=myNewArrayList(16)
label18.Text=myNewArrayList(17)
label19.Text=myNewArrayList(18)
label20.Text=myNewArrayList(19)
End Class
It looks like you're trying to grab your array from session and assign the values to your labels directly after your class declaration. You have to do this inside a method or event handler in your class. I would recommend doing it in Page_Load or in a seperate
method in your class that you then call from Page_Load.
HTH,
Bruno
If this post answered your question please remember to 'Mark as Answer'!
Ok, I figured it at but I have another problem on my first page. I get an error on myArrayList(0),
variable 'myArrayList' is used befored it has been assigned a valued. I don't understand that one, any help?
thanks
Partial Class register_Default
Inherits System.Web.UI.Page
Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myArrayList As ArrayList
myArrayList(0) = DOTAgency.SelectedItem.Text
myArrayList(1) = ServiceType.SelectedItem.Text
myArrayList(2) = CertificationInfo.SelectedItem.Text
myArrayList(3) = Certification.Text
Thanks, I realized that and fix that portion but have an issue on my forms page with the ArrayList. I getting,
variable 'myArrayList' is used befored it has been assigned a value'.
Partial Class register_Default
Inherits System.Web.UI.Page
Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myArrayList As ArrayList
myArrayList(0) = DOTAgency.SelectedItem.Text
myArrayList(1) = ServiceType.SelectedItem.Text
myArrayList(2) = CertificationInfo.SelectedItem.Text
myArrayList(3) = Certification.Text
gmcghee
Participant
929 Points
251 Posts
Declaration Expected on Label.Text
Apr 18, 2006 02:24 PM|LINK
I'm using an ArrayList to pass the values from the form to another page. This page has a bunch of Label boxes to display the information. When I set the value I get a "declaration expected" for the label1.text. Why am I getting this and how do I fix it?
thanks
grady
register2.aspx.vb
Partial Class register_register2
Inherits System.Web.UI.Page
Dim myNewArrayList As ArrayList = Session("ddlArrayList")
Label1.Text=myNewArrayList(0)
label2.Text=myNewArrayList(1)
label3.Text=myNewArrayList(2)
label4.Text=myNewArrayList(3)
label5.Text=myNewArrayList(4)
label6.Text=myNewArrayList(5)
label7.Text=myNewArrayList(6)
label8.Text=myNewArrayList(7)
label9.Text=myNewArrayList(8)
label10.Text=myNewArrayList(9)
label11.Text=myNewArrayList(10)
label12.Text=myNewArrayList(11)
label13.Text=myNewArrayList(12)
label14.Text=myNewArrayList(13)
label15.Text=myNewArrayList(14)
label16.Text=myNewArrayList(15)
label17.Text=myNewArrayList(16)
label18.Text=myNewArrayList(17)
label19.Text=myNewArrayList(18)
label20.Text=myNewArrayList(19)
End Class
register2.aspx
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="register2.aspx.vb" Inherits="register_register2" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="index" Runat="Server">
<div style="text-align:left">
<h1>This worked</h1>
DOT Agency: <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br />
Service Type: <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <br />
Certification Information: <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> <br />
Certification Date: <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label> <br />
Web IP Address: <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label> <br />
Web Name: <asp:Label ID="Label6" runat="server" Text="Label"></asp:Label> <br />
bpag
Contributor
3517 Points
533 Posts
Re: Declaration Expected on Label.Text
Apr 18, 2006 03:04 PM|LINK
HTH,
Bruno
gmcghee
Participant
929 Points
251 Posts
Re: Declaration Expected on Label.Text
Apr 18, 2006 03:09 PM|LINK
Ok, I figured it at but I have another problem on my first page. I get an error on myArrayList(0), variable 'myArrayList' is used befored it has been assigned a valued. I don't understand that one, any help?
thanks
Partial Class register_Default
Inherits System.Web.UI.Page
Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myArrayList As ArrayList
myArrayList(0) = DOTAgency.SelectedItem.Text
myArrayList(1) = ServiceType.SelectedItem.Text
myArrayList(2) = CertificationInfo.SelectedItem.Text
myArrayList(3) = Certification.Text
gmcghee
Participant
929 Points
251 Posts
Re: Declaration Expected on Label.Text
Apr 18, 2006 03:15 PM|LINK
Thanks, I realized that and fix that portion but have an issue on my forms page with the ArrayList. I getting, variable 'myArrayList' is used befored it has been assigned a value'.
Partial Class register_Default
Inherits System.Web.UI.Page
Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myArrayList As ArrayList
myArrayList(0) = DOTAgency.SelectedItem.Text
myArrayList(1) = ServiceType.SelectedItem.Text
myArrayList(2) = CertificationInfo.SelectedItem.Text
myArrayList(3) = Certification.Text
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: Declaration Expected on Label.Text
Apr 18, 2006 03:31 PM|LINK
I don't do much VB, but shouldn't
Dim myArrayList As ArrayList
be
Dim myArrayList As New ArrayList()
and:
myArrayList(0) = DOTAgency.SelectedItem.Text
' etc ...
should be:
myArrayList.Add(DOTAgency.SelectedItem.Text)
NC...