locked
not able to retrieve session variable's value RRS feed

  • Question

  • User2031860760 posted

    i m getting a error in accessing the session variable which i hv put in cs file....m attaching tha error below....thnx in advance

    Compiler Error Message: BC30203: Identifier expected.

    Source Error:

    Line 147:                                        
    Line 148:                                          <br />
    Line 149: <strong>IP Address: <% Response.Write(Session["ipaddress"]); Line 150:                                                                    %></strong>&nbsp;
    Line 151:                                         </td>
    Wednesday, September 28, 2011 7:15 AM

Answers

  • User210672981 posted

    Hi

    <form id="form1" runat="server">
        <div>
            <strong>IP Address:
                <asp:Label ID="Label2" runat="server" Text='<%#Session["ipaddress"]%>'></asp:Label>
            </strong>
        </div>
        </form>
    protected void Page_Load(object sender, EventArgs e)
            {
                Session["ipaddress"] = "www.microsoft.com";
                Page.DataBind();
            }

    Hope it can help.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 30, 2011 1:24 AM

All replies

  • User-366017857 posted
    Do like this

    <strong>IP Address: '<%=Response.Write(Session["ipaddress"]);%>'</strong>
    or

    <strong>IP Address: '<%=Session["ipaddress"]%>'</strong>

    Wednesday, September 28, 2011 9:14 AM
  • User2031860760 posted

    1st 1 giving error dat expression does not produce ny value.....and in second error is same as above,....

    Wednesday, September 28, 2011 9:21 AM
  • User2031860760 posted

    1st 1 giving error dat expression does not produce ny value.....and in second error is same as above,....

    Wednesday, September 28, 2011 9:21 AM
  • User-366017857 posted

    You need to use lable

    Use lable and set its text as session value

    <strong>IP Address: <asp:lable id="lblAddress" runat="server" Text='<%=Session["ipaddress"]%>'></asp:lable></strong>
    Thursday, September 29, 2011 1:51 AM
  • User2031860760 posted

    thnx for helping out....the error is removed bt its not showing me the session value....its giveing the output as mentioned below....hope u ll reply me....thnx for giving me yo time...

    Your Login Details
    Last Login
    Date & Time:  
    IP Address:  <%=Session["ipaddress"]%>
    Thursday, September 29, 2011 7:50 AM
  • User830400798 posted

    hi

    i dnt know what exctly problem but i feel that session["name"] returnthe object and label required text value so you need to upcasting of session value in to string value.

    Thursday, September 29, 2011 7:58 AM
  • User2031860760 posted

    its not working...i had tried with tostring() method also.....:(.....

    Thursday, September 29, 2011 8:14 AM
  • User830400798 posted

    ok just try this

    <#%=
    eval("Session["""mySessionKey"""]") %>
    
    Thursday, September 29, 2011 8:38 AM
  • User2031860760 posted

    stilll same problem msg m metioning below...

    Your Login Details
    Last Login
    Date & Time:  
    IP Address:   <#%=eval("Session["""ipaddress"""]") %>



    Thursday, September 29, 2011 9:13 AM
  • User210672981 posted

    Hi

    <form id="form1" runat="server">
        <div>
            <strong>IP Address:
                <asp:Label ID="Label2" runat="server" Text='<%#Session["ipaddress"]%>'></asp:Label>
            </strong>
        </div>
        </form>
    protected void Page_Load(object sender, EventArgs e)
            {
                Session["ipaddress"] = "www.microsoft.com";
                Page.DataBind();
            }

    Hope it can help.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 30, 2011 1:24 AM
  • User2031860760 posted

    thanxx yo answer help me lot i just dont no bout page.databind()......it helps me thnx a lot.....

    Friday, September 30, 2011 2:44 AM
  • User2031860760 posted

    i have nt written the script i just done ma coding in page_load n put the value on appropriate labels....hope it help others also....thnx ol for being so supportive....

    Friday, September 30, 2011 2:45 AM