I am trying to migrate the code of jquery to reactjs and i am failing to achieve it. Folder structure :
MasterPage.master (aspx)
1. Client.aspx
2. Session.aspx
2.1 Session.js
I am trying to remove this js and add a jsx file which has the react content instead of jquery.
Doubts: 1. how can i access the DOM element in master page from jsx
var navButton = document.getElementById("HyperlinkNavigation");
How can i use the beginrequest and endrequest in react?
var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_beginRequest(BeginRequestHandler); prm.add_endRequest(EndRequestHandler);
masterpage.master
<!DOCTYPE html>
<head>
</head>
<body id="BodyMasterPage" runat="server">
<form id="AppPortalFormPage" runat="server" enableviewstate="true" class="container">
<asp:Panel runat="server" ID="PanelLayout" CssClass="container__center">
<div class="main" id="mainDiv" runat="server">
<asp:ContentPlaceHolder ID="ContentPlaceHolderMiddlePanel" runat="server">
<%-- The content middle part to be filled in the pages --%>
</asp:ContentPlaceHolder>
<div class="navigation" id="navigationDiv">
<asp:Hyperlink ID="HyperlinkNavigation" runat="server"/>
<asp:LinkButton ID="LinkButtonAbout" CssClass="navigation__logo" runat="server" OnClientClick="javascript:showAboutLayer();return false;" OnLoad="LinkButtonAbout_Load"/>
</div>
</div>
</asp:Panel>
</form>
</body>
</html>
session.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeBehind="session.aspx.cs" Inherits="AppPortal.sessionPage" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="ContentPlaceHolderMiddlePanel" runat="Server">
<script>
let userActivity = true;
let scroolBarPlaceHolder = '<%= ClientID %>';
</script>
<script src="Scripts/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/react@15/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/babel" src="includes/scripts/session.js"></script>
<div class="sessionmanager">
<div id="session_root"></div>
</div>
</asp:Content>
session.js
navButton.className = "navigation__button navigation__button--back";
// attach activity tracker on masterpage
$(this).on('mousedown touchstart mousewheel keydown', function () {
userActivity = true;
});
navButton.onclick = function () {
//history.back(); terminate postback writes to browser history
navButton.href="applications.aspx";
};
// Register request handlers to set scroll bar on the correct position when table is refreshed.
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
// Get X and Y positions of scrollbar before the partial postback
xPos = $get(scroolBarPlaceHolder).scrollLeft;
yPos = $get(scroolBarPlaceHolder).scrollTop;
}
function EndRequestHandler(sender, args) {
// Set X and Y positions back to the scrollbar after partial postback
$get(scroolBarPlaceHolder).scrollLeft = xPos;
$get(scroolBarPlaceHolder).scrollTop = yPos;
}
});
setInterval(function () { makePing(socketID, userActivity); }, 5000);
document.querySelectorin React code. But I would strongly recommend to not go this route and use React how it is meant to work instead of hacking around it.