Monday 16 August 2021

ASP.Net Access Session Values in JavaScript with example (Client Side)

In this post, we will learn how to access the ASP.Net session variable in JavaScript with example or ASP.Net access session value in jQuery with example or access session values in client-side using JavaScript with example or ASP.Net get session variables in JavaScript with example or get ASP.Net session variable values in client-side in C#, VB.Net with example.

By using the “Session” property we can easily access session variable value in JavaScript or jQuery based on our requirements.

ASP.Net (HTML) Code - 

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="PracticeProject.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Asp.Net Access Session Value in JavaScript or jQuery</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        $(function () {
            var name = 'Welcome to ' + '<%= Session("BlogName") %>';
            $('#headerText').text(name)
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div align="center">
            <h1><u>Asp.Net Access Session Value in JavaScript or jQuery</u></h1>
            <br />
            <h2 id="headerText"></h2>
        </div>
    </form>
</body>
</html>


VB.Net (HTML) Code - 

 Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Session("BlogName") = "Programming Trends"
    End Sub

End Class

Result -

ASP.Net Access Session Values in JavaScript with example (Client Side)



0 comments:

Post a Comment

Please do not enter any spam link in the message box.