Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to call c# method in javascript

Posted on 2012-04-05
2
Medium Priority
?
511 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 9

Accepted Solution

by:
sachinpatil10d earned 2000 total points
ID: 37810312
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
ID: 37810317
In your code just change this

<%logout()%> ;

to

<%logout();%>
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

715 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