Convert VB Code to C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Eleven
    New Member
    • Mar 2008
    • 19

    Convert VB Code to C#

    Hi,

    Can someone please help me convert this code snippet from VB to C#

    [CODE=VB]<% If Session("Partne rLoggedIn") Then %>Partner User logged in: <b><%=Session(" PartnerUserName ")%></b> - on behalf of - <% End If%>Logged in as: <b><%=Session(" user")%></b>[/CODE]

    Thanks!
    Last edited by Eleven; Aug 15 '08, 08:33 AM. Reason: left out something
  • Eleven
    New Member
    • Mar 2008
    • 19

    #2
    The code's actually on an ASP page, want to put it on an ASPX C# page.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Put brackets around Session, add { after the brackets closing the Session,remove the Then and replace the End IF with a }.

      Comment

      • Eleven
        New Member
        • Mar 2008
        • 19

        #4
        Thanks!

        I tried this and I get an "Identifier expected"error!

        Code:
        <% If (Session["PartnerLoggedIn"]) { %>Partner User logged in: <b><%=Session("PartnerUserName")%></b> - on behalf of - <%}%>Logged in as: <b><%=Session("user")%></b>

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Use small caps i for if.

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            You need to use brackets [] for all the session objects, and you might need to add .ToString() on to them, because they are stored as objects.

            Also, I would suggest you rewrite this snippet, replacing all the server tags with <asp:Label> tags, and filling their value in the Page_Load method of the C# codepage. You're doing things the "classic" way.

            Comment

            Working...