Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello,

I am trying to call Jquery Function from a Codebehind Webmethod by below line but i am not able to call it

C#
ScriptManager.RegisterStartUpScriptBlock(this,this.gettype(),"myfun","myFunction()",true)
Posted
Comments
F-ES Sitecore 8-May-15 6:12am    
You can't call javascript from code behind, all your function is doing is writing the given javascript to the page output so that when the .net code finished creating the page and passes it to the client, the client will then execute the js.

However as webmethods are not streaming html output to the client your js won't be injected into the page anyway so you're code just simply isn't going to work. The js that calls your webmethod has to do all the work, ie it needs to call "myFunction" on the "success" event of the webmethod call.
Richard Deeming 8-May-15 7:33am    
This comment should be a solution. :)
F-ES Sitecore 8-May-15 7:58am    
I know what you're saying but I don't like adding "you can't do this" as asolution as it might be the answer to the question, but it's not a solution to his problem which he still has :)
ZurdoDev 8-May-15 8:57am    
Sure it is a solution. All you have to add is that the webmethod should return a value and then from the JavaScript call the other function. After all, chances are he's calling the webmethod from JS anyway to begin with.
Sinisa Hajnal 8-May-15 7:42am    
Sitecore for the win! Add it as a solution and I'll five it :)

1 solution

I was going to answer this, but found F-ES Sitecore has added an awesome comment, which is actually the answer.

WebMethods are meant to take some input and return the result. You should not initiate a client script from that and why to? You are already doing operations on client scripts and when you get the result from the WebMethod, then inside the Ajax Success method, execute whatever JavaScript Code you want to. That will be very easy.
 
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