Trying to understand order of events, variable settings, property settings, etc… between ASP.NET and JQuery/JavasSript. I show a basic, snipped example below to try to explain my question.
In ASP.NET code-behind I created both a public property and variable (to catch any differences) which values are set during the Page Load event. Then a script from the front of the page, I retrieve the values from the ASP.NET property and variable inline, within my jQuery/JavaScript code and write it to the console.
My intention for this in my real project is to retrieve values from ASP.NET that I can pass on to JavaScript. This works, but I’m not clear why. I thought client-side scripts ran before server-side scripts, so how do these values get picked up? How do I determine the order of everything?
ASP.NET page:
<%@ Page Language="VB" ... blah ... %>
<!doctype html>
<html lang="en">
<head runat="server">
<title>My ASP.NET Page</title>
</head>
<body>
<form id="form1" runat="server">
<p>Basic Example</p>
</form>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" ...blah...></script>
<script>
$(document).ready(function () {
console.log("MyAspnetProperty = " + "<%= MyAspnetProperty %>");
console.log("MyAspnetVariable = " + "<%= MyAspnetVariable %>");
});
</script>
</body>
</html>
My code behind
Partial Class my_aspnet_page
Inherits System.Web.UI.Page
Public Property MyAspnetProperty As String
Public MyAspnetVariable As String
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
MyAspnetProperty = "ASP.NET Property Value"
MyAspnetVariable = "ASP.NET Variable Value"
End Sub
End Class




