Solved

how to call c# method in javascript

Posted on 2012-04-05
2
481 Views
Last Modified: 2012-04-05
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
Comment
Question by:R8VI
  • 2
2 Comments
 
LVL 9

Accepted Solution

by:
sachinpatil10d earned 500 total points
Comment Utility
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
 
LVL 9

Expert Comment

by:sachinpatil10d
Comment Utility
In your code just change this

<%logout()%> ;

to

<%logout();%>
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now