Access C# code from .JS javascript file
I am trying to put a c# code when a js function happens. I found this article https://www-archive.mozilla.org/js/spidermonkey/tutorial.html but I didn't fully understand how to do it in my case. Here is what I tried.
rooms.aspx
<script type="text/javascript" language="Javascript">
function DetectBrowserExit()
{
// alert('Execute task which do you want before exit');
<%
if(Application["player1"]==Session["mynick"])
{
Application["player1"]="";
Application["status1"]=false;
}
%>
}
window.onbeforeunload = function () { DetectBrowserExit(); }
</script>
All that goes in the head of the as开发者_StackOverflow中文版px and DetectBrowserExit happens when a user closed the browser.
You know how to make the C# code accessible?
Thank you.
You can use page methods with a script manager to do this.
Using Page Methods in ASP.NET AJAX
精彩评论