Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
my code is like this
<HTML>
<HEAD>
<script type="text/javascript" language="JavaScript">
function alertMe() {
var box = document.getElementById("myTextBox");

-------------------------------------------------------
}
</script>
</HEAD>
<BODY>
<INPUT type="text" id="myTextBox"  önkeyup="alertMe()">
</INPUT>


Initial Contents of the div 'logBox'

</BODY>
</HTMl>



in the ----------------------------------- i need to call a c# function can any one suggest me with examples....
Posted
Updated 8-Sep-11 21:20pm
v3
Comments
Dalek Dave 9-Sep-11 3:21am    
Edited for Code Block.

Please follow below any item:

1. Write a function in code behind with public/protected modifier and then call as below:
<%= YourCodeBehindFunctionName() %>


2. If you want to call a function from your business layer then call the function as, the function must be static:
<%= NamespaceName.ClassName.YourFunctionName() %>
 
Share this answer
 
JavaScript
<%=nameOfTheFunction()%>
 
Share this answer
 
Comments
Kartheek.chakrala 9-Sep-11 4:37am    
please fulfill ur answer? with an example. ur answer is valued to me..
hilmisu 9-Sep-11 4:44am    
in your function (with the one in javascript)

function alertMe() {
var box = document.getElementById("myTextBox");

<%=nameOfTheFunction()%> //this function is in your c# side which you wanted to call.
}

This is simple and usefull to call a c# side function in your javascript.
Member 8090436 24-Jul-12 12:40pm    
Not able to call..it says 'name 'functionname' does not exists in the current context.'
I tried but failed :-)
Please refer my article related to the same, use JQuery instead of javascript and will be easy to implement

Calling C# method using JQuery client side[^]

Use can even look at the alternate solution

Calling a C# method using jQuery on the client side[^]
 
Share this answer
 
 
Share this answer
 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900