Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 514
  • Last Modified:

how to call c# method in javascript

Hi,

I have the following method in c#

public void logout()
        {
          
        

        }

Open in new window


and the following code in javascript

<script type="text/javascript">
    window.onunload = function unloadEvent() {
    <%logout()%> ; 
        
    }           
</script>

which gets called like so 

<body onbeforeunload="unloadEvent()">

But i get the following error 
 CS1002: ; expected

Line 8:  <script type="text/javascript">
Line 9:      window.onunload = function unloadEvent() {
Line 10:     <%logout()%> ; 
Line 11:         
Line 12:     }   

please help 

Thanks,

R8VI 

Open in new window

0
R8VI
Asked:
R8VI
  • 2
1 Solution
 
sachinpatil10dCommented:
Try this

Code behind
    public void logout()
    {
    }

Open in new window


client page
<script type="text/javascript">
    window.onunload = unloadEvents;
    function unloadEvents() 
    {
    <% logout(); %>
        
    }           
</script>

Open in new window

0
 
sachinpatil10dCommented:
In your code just change this

<%logout()%> ;

to

<%logout();%>
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now