My answer is similar to what others said to get a hidden variable / control that can be passed back to the server side code, like as a Button or Page_Load event, etc. I got an idea from them. But here it is:
<asp:TextBox ID="hdnErrorMsg" ClientIDMode="Static" style="display: none;" runat="server"/>
This can be installed in JavaScript, and it will return to the server side of Asp.NET and will be used and verified. If you want to save it when it returns to the customer, you may have to return it and all other things that you need. In my case, this is an error message. I wanted him to stop at the ASP.NET button click event to save and exit, but I needed to return an error message so that when he returned to the client he was there again.
source share