Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Genius!!

is it possible to call the C# function from javascript lanaguage with out using the services
Posted
Comments
Anuja Pawar Indore 30-Jan-12 7:53am    
Use JQuery and can be done easily

 
Share this answer
 
1. ScripManager's property EnablePageMethods="true"
2. Create your Static method with attribute [WebMethod]
3. Call from javascript as PageMethods.methodName();
 
Share this answer
 
Comments
vivek.khatri 3-Jan-14 13:19pm    
Hello Sanjay, I have a problem. I have defined my method with [WebMethod] attribute, added a ScriptManager with EnablePageMethods="True" but still, I can't find "PageMethods" in javascript intellisense..

I am using VS 2010 Ultimate with SP1, .Net Framework 4.0 with C# as server side language..

Please help me out, even if I write "PageMethods" in javascript function, it can't list my method in intellisense...
Sanjay K. Gupta 4-Jan-14 0:37am    
Your method must be public and static
vivek.khatri 4-Jan-14 1:19am    
Yes, my method is already defined as public and static.. Still can't find any "PageMethods" in javascript function intellisense..

here is the link to the screenshot of my snippets..

Javascript Intellisense : http://sdrv.ms/1crYEUu

Code Behind : http://sdrv.ms/1crYGvF

please help me out ASAP.... :P
Sanjay K. Gupta 4-Jan-14 3:53am    
PageMethods are not visible in intellisense, But you can call as PageMethods.yourMethodName
vivek.khatri 4-Jan-14 4:04am    
Yes sir I got what you are saying but still it isn't working...

sample screenshot : http://sdrv.ms/1cP1Fzl
hi it'simple solution

first decleare your function into c#

public void clear()
{
textbox.text=string.empty;
}

call into javascript

]]>
 
Share this answer
 
func(){


var result=<%#Getnames()%>;
}




in c#

public string Getnames()
{
return "";
}
 
Share this answer
 

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