Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7849815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:39:00+00:00 2026-06-02T18:39:00+00:00

Within my C# code behind page, I have the following: MembershipUser currentUser = Membership.GetUser(false);

  • 0

Within my C# code behind page, I have the following:

MembershipUser currentUser = Membership.GetUser(false);

HttpContext.Current.Session["UserGuidAsString"] = currentUser.ProviderUserKey.ToString();

At the bottom of the corresponding ASPX page, I have the following code:

</form>
<script type="text/javascript"> var userGuidAsString = '<%=Session["UserGuidAsString"]%>';
                                alert(userGuidAsString);
</script>
</body>
</html>

It gives the proper expected result which is an alert box with the User’s GUID when I run the page

I wanted to move the JavaScript code to a .js file so that the code is more modularized and organized.
I created the following test.js javascript file with the following contents:

var userGuidAsString = '<%=Session["UserGuidAsString"]%>';
alert(userGuidAsString);

I also modified the ASPX page so that it would include the test.js javascript file:

</form>
    <script src="/Scripts/test.js" type="text/javascript"></script>
    </script>
</body>
</html>

It fails because it just gives an alert box with
‘<%=Session[“UserGuidAsString”]%>’
as a message

May I please know how I can make in line server C# code work within JavaScript .js files?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:39:02+00:00Added an answer on June 2, 2026 at 6:39 pm

    By This your accessing Server Variable

    '<%=Session["UserGuidAsString"]%>'
    

    its not functionlity of Javascript.

    You can write this code without js block also..
    its like ASP code..
    so its workg with .aspx page only not in javascript

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code within a stored procedure. WHERE WPP.ACCEPTED = 1 AND
Background: I'm creating a very simple chatroom-like ASP.NET page with C# Code-Behind. The current
ok, i have the following class in my code behind file. it's a very
I'm using the following code within the JCProperty class to retrieve data from a
I'm using the following code within a VB 6.0 application to allow give the
I'm using the following code within XCode, building for iOS with ARC enabled. Why
I have an asp.net page with a multiview control nested within another multiview control.
Instead of a *.cs code behind or beside I'd like to have a *.js
I have an aspx page title tag like the following : <title> XXXX-content page
I have a standart Page within my ListView control on the page, And the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.