Access Session value in other page using C# and VB.Net in ASP.Net

Last Reply 2 months ago By arunkurmi

Posted 2 months ago

Hello,

I have the code below that carry from another page, but then somehow only read the first “If statement”, and can’t pass it on to the second "If Statement" if is not true.

Please help.

Page 1:

HTML:

<table>
    <tr>
        <td>
            <p class="padding2">
                <asp:LinkButton ID="IndexAdminComp" runat="server">* Administrative/Computer</asp:LinkButton></p>
        </td>
        <td>
            <asp:Label ID="AdminComplbl" runat="server" Text="1" Font-Size="28px" Font-Names="Arial"
                Visible="false"></asp:Label>
        </td>
    </tr>
    <tr>
        <td>
            <p class="padding2">
                <asp:LinkButton ID="IndexChildYouth" runat="server">* Child/Youth</asp:LinkButton></p>
        </td>
        <td>
            <asp:Label ID="ChildYouthlbl" runat="server" Text="2" Font-Size="28px" Font-Names="Arial"
                Visible="false"></asp:Label>
        </td>
    </tr>
</table>

VB Code:

Protected Sub IndexAdminComp_Click(sender As Object, e As EventArgs) Handles IndexAdminComp.Click
    Response.Redirect("~/Agency/Report/GlobalAgencyTemplate.aspx")
    Session("One") = AdminComplbl.Text
End Sub 

Protected Sub IndexChildYouth_Click(sender As Object, e As EventArgs) Handles IndexChildYouth.Click
    Session("Two") = ChildYouthlbl.Text
    Response.Redirect("~/Agency/Report/GlobalAgencyTemplate.aspx")
End Sub

Page 2:

HTML:

<table>
    <tr>
        <td>
            <p class="padding10">
                <asp:Label ID="AClbl" runat="server" Text="" Font-Size="24px" Font-Bold="true"></asp:Label></p>
        </td>
</table>

VB Code:  here is the place that can't read the second "If"

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If AClbl.Text = Session("Two") Then
        GetFieldwork("QChildYouthService_sp")
        AClbl.Text = "CHILD/YOUTH"
    End If
    If AClbl.Text = Session("One") Then
        GetFieldwork("QAdministrativeComputers_sp")
        AClbl.Text = "Adminstrative/Computer"
    End If
End Sub

 

You are viewing reply posted by: arunkurmi 2 months ago.
Posted 2 months ago
phonghue says:
 If Session("message") = "One" Then
        lblMessage.Text = "Adminstrative/Computer"
        GetFieldwork("QAdministrativeComputers_sp")
    ElseIf Session("message") = "Two" Then
        lblMessage.Text = "Child/Youth"
        GetFieldwork("QChildYouthService_sp")
    End If

 You have assigned value as 1 and 2 and checking the session value with One and Two. So condition will not be matched.

You need to check with 1 and 2 or change the Label Text with One and Two.