Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
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 8-Sep-11 19:46pm
Edited 8-Sep-11 21:20pm
Dalek Dave432.4K
v3
Comments
Dalek Dave at 9-Sep-11 3:21am
   
Edited for Code Block.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can do this using pagemethods in asp.net AJAX.
 
check these out:
 
http://www.dotnetfunda.com/articles/article454-using-pagemethods-and-json-in-aspnet-ajax-.aspx[^]
 
http://www.dotnetcurry.com/ShowArticle.aspx?ID=109[^]
 
hope it helps Smile | :)
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

    <%=nameOfTheFunction()%>
  Permalink  
Comments
Kartheek.chakrala at 9-Sep-11 4:37am
   
please fulfill ur answer? with an example. ur answer is valued to me..
hilmisu at 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 at 24-Jul-12 12:40pm
   
Not able to call..it says 'name 'functionname' does not exists in the current context.'
I tried but failed :-)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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() %>
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 853
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 166
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 3 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100