I’m developing an ASP.NET application and have encountered an issue with my user control. While the user control loads up fine on the main page and the C# backend executes without any problems, the JavaScript and jQuery functions contained within the control are not functioning at all.
The debugger shows that the page load event is firing, and the C# code is running properly. However, my jQuery function FETCH_PROJECTS_DATA is never called, which is very frustrating because I need both server-side and client-side code to communicate effectively.
Here’s how I have set up my main page:
<%@ Page Title="" Language="C#" MasterPageFile="~/WebPages/masterPage.Master" AutoEventWireup="true" CodeBehind="mainPage.aspx.cs" Inherits="MyWebApp.WebPages.mainPage" EnableEventValidation="false" %>
<%@ Register Src="~/UserControls/UserControl_Projects.ascx" TagPrefix="uc" TagName="UserControl_Projects" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<uc:UserControl_Projects runat="server" />
</asp:Content>
And here’s the code for my user control:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserControl_Projects.ascx.cs" Inherits="MyWebApp.UserControls.UserControl_Projects" %>
<div class="dashboard-container">
<div class="dashboard-content">
<div id="projects-card" class="card">
<div class="card-header">
<h4 class="card-title text-center">
<label id="projLabel" runat="server" clientidmode="Static">Projects Overview</label>
</h4>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-6 project-table">
<div class="table-card">
<div class="table-header">
Ongoing Projects
</div>
<div class="table-body">
<table id="ongoingProjects" class="table table-bordered">
<thead></thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<div class="col-md-6 project-table">
<div class="table-card">
<div class="table-header">
Completed Projects
</div>
<div class="table-body">
<table id="completedProjects" class="table table-bordered">
<thead></thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function () {
if ($("#userPerm").val() == "admin") {
FETCH_PROJECTS_DATA();
}
});
</script>
What might be preventing the JavaScript from running when the user control is loaded?