Writing Session Variable Information To a Table

  • Thread starter Thread starter Michelle A.
  • Start date Start date
M

Michelle A.

I have a four page form. Pages 1-3 stores there information in a session
variables. Page four is reached (a final review page) and then the
information will be written to the SQL server.

When I tried to enter some code in the HTML table by hand so I could get it
to show up in the right place. For example I use this code in the HTML
table:

<td><%=sessionvar1%><%=sessionvar2%></td>

Compile and run, when I get to the 4th page it says that sessionvar1 has not
been declared. Can I use session variables this way to display the
information?
 
Justin, thanks for your reply.

I tried doing that way. The only problem doing it this way is this
information is coming from a series of check boxes on the first page. So it
will vary the amount of information that will be displayed on the summary
page. If I put all these label fields in that cell of the table, it will
space it out and leave a huge gap. What I was looking to for was something
that would allow the cell to conform to the amount of information that will
be presented.

Thanks again.
 
concatenate


Michelle A. said:
Justin, thanks for your reply.

I tried doing that way. The only problem doing it this way is this
information is coming from a series of check boxes on the first page. So it
will vary the amount of information that will be displayed on the summary
page. If I put all these label fields in that cell of the table, it will
space it out and leave a huge gap. What I was looking to for was something
that would allow the cell to conform to the amount of information that will
be presented.

Thanks again.
 
Let me add some code:

Here is the code behind page: (I know this might not be the most efficent
way )

An if statement checks what check boxes were checked and displays them to
the correct label in the table:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Session("Gifttoag") Then
Me.Label1.Text = "College of Agriculture"
Else
Me.Label1.Text = ""
End If
If Session("Gifttobus") Then
Me.Label2.Text = "College of Buisness "
Else
Me.Label2.Text = ""
End If
If Session("Gifttodesign") Then
Me.Label3.Text = "College of Design"
Else
Me.Label3.Text = ""
End If
If Session("Gifttoedu") Then
Me.Label4.Text = "College of Education"
Else
Me.Label4.Text = ""
End If
If Session("Gifttoengin") Then
Me.Label5.Text = "College of Engineering"
Else
Me.Label5.Text = ""
End If
If Session("Gifttofcs") Then
Me.Label6.Text = "College of Family and Consumer Sciences"
Else
Me.Label6.Text = ""
End If
If Session("Gifttolas") Then
Me.Label7.Text = "College of Liberal Arts and Sciences"
Else
Me.Label7.Text = ""
End If
If Session("Gifttovetmed") Then
Me.Label8.Text = "College of Veterinary Medicine"
Else
Me.Label8.Text = ""
End If
If Session("Gifttolibrary") Then
Me.Label9.Text = "University Library"
Else
Me.Label9.Text = ""
End If
If Session("Gifttomorrill") Then
Me.Label10().Text = "Morrill Hall Restoration Project"
Else
Me.Label10.Text = ""
End If
If Session("Gifttoarea") Then
Me.Label11().Text = "Area of Greatest Need"
Else
Me.Label11.Text = ""
End If

Me.Label12.Text = Session("Gifttoother")
Me.Label13.Text = Session("GiftAmount")
End Sub


Here is the HTML section where the information is displayed in the table.



<tr>
<td style="WIDTH: 268px; HEIGHT: 21px" align="left">Gift
Desgination(s):</td>
<td align="center" style="HEIGHT: 21px">

<asp:Label id="Label1" runat="server">Label</asp:Label>

<asp:label id="Label2" runat="server">Label</asp:label>
<asp:label id="Label3" runat="server">Label</asp:label>
<asp:label id="Label4" runat="server">Label</asp:label>
<asp:label id="Label5" runat="server">Label</asp:label>
<asp:label id="Label6" runat="server">Label</asp:label>
<asp:label id="Label7" runat="server">Label</asp:label>
<asp:label id="Label8" runat="server">Label</asp:label>
<asp:Label id="Label9" runat="server">Label</asp:Label>
<asp:Label id="Label10" runat="server">Label</asp:Label>
<asp:Label id="Label11" runat="server">Label</asp:Label>
<asp:Label id="Label12" runat="server">Label</asp:Label>
</td>
</tr>
 
I usually use the code behind but it doesn't make much difference I don't
suppose. I also use a delimiter which makes it easier to use the resultant
string later.

HTH
 
Michelle,

I understand you don't know how many checkboxes values will need to be
displayed.

Do you know how to add labels to a control dynamically? I think this would
be the best solution.

Put a placeholder control in the table cell. Then dynamically create a label
for every check box that's checked and then add that label to the
placeholder.

'---Sample Code

If Session("Gifttoag") Then
Call AddLabel("College of Agriculture")
End If

If Session("Gifttobus") Then
Call AddLabel("College of Buisness ")
End If

If Session("Gifttodesign") Then
Call AddLabel("College of Design")
End If

'---This subroutine adds a label to the placeholder
Private Sub AddLabel(ByVal textToAdd As String)
Dim Label As New Label
Label.Text = textToAdd
Placeholder1.Controls.Add(Label)

Dim Literal As New LiteralControl
Literal.Text = "<br>"
Placeholder1.Controls.Add(Literal)
End Sub


Sincerely,
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Back
Top