if(httpRequest.readyState == 4 && httpRequest.status == 200)
{
<% SetText(); %>
}
I need to call method from code behind in javascript. Method is obviously called SetText() and it's void.
This I tried didn't work.
if(httpRequest.readyState == 4 && httpRequest.status == 200)
{
<% SetText(); %>
}
I need to call method from code behind in javascript. Method is obviously called SetText() and it's void.
This I tried didn't work.
You have to expose the C# method using a service or a handler. Depending on your architecture the handler can be implemented in different ways (MVC, .net HttpHandler, JayRock handler, etc.). And then you have to call the method from Javascript using an AJAX request.
And remember, avoid to embed CSharp code blocks inside server side generated Javascript code.
References:
It is not possible, at least if you don't make an AJAX request. Otherwise, it's impossible to access server-side methods via client-side(in this case via JS).
H i answered a similar question on Calling a C# method from Javascript I provided an example using AJAX: Call C# method in javascript function directly
Hope this will help.
Make one ajax call, there you check whether the connection is ok or not. If connection is ok make the actual call there itself(in server side) and return data.
Since you made an async request you page data is not going to show any error message. Even if there is some error you will get in error handler and you know what to do when error occur.
There should not be any scenario when the client code has to contact server method directly. You can always do work around with that in case your design is like that.
try this link http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/calling-an-Asp-Net-C-Sharp-method-web-method-using-javascript/
yes but it is not possible without ajax call :(.
And please make sure you have imported all the necessary jquery files and the function that you have written for ajax call should be a "STATIC".
rest will be cleared please follow the link