Not able to call .NET function with return value in javascript
-
ASP.NET function: public int withparam(int x) { int y; y = x + 10; return y; } HTML button function Button1_onclick() { <% var st = withparam(10); %>; document.write(st); } When i click on button, it says var st could not be found. Please let me know where the syntax is wrong and is this the right way
-
ASP.NET function: public int withparam(int x) { int y; y = x + 10; return y; } HTML button function Button1_onclick() { <% var st = withparam(10); %>; document.write(st); } When i click on button, it says var st could not be found. Please let me know where the syntax is wrong and is this the right way
you are getting this error as you have declared variable 'st' in <% %> block, means it is declared server side and you are using it at client side. so declare it at client side and assign value by calling server side method.
var st;
st = <% withparam(10) %>;
document.write(st); -
you are getting this error as you have declared variable 'st' in <% %> block, means it is declared server side and you are using it at client side. so declare it at client side and assign value by calling server side method.
var st;
st = <% withparam(10) %>;
document.write(st); -
I have applied your code. st = <% withparam(10) %>;->It does not work. Please let me know the solution.
amittinku wrote:
It does not work.
what does mean by this? do u got some error or what?
-
I have applied your code. st = <% withparam(10) %>;->It does not work. Please let me know the solution.
-
Replace the line
st = <% withparam(10) %>;
with this
st = <%= withparam(10) %>;
it would work surely. i have tested it.
-
ASP.NET function: public int withparam(int x) { int y; y = x + 10; return y; } HTML button function Button1_onclick() { <% var st = withparam(10); %>; document.write(st); } When i click on button, it says var st could not be found. Please let me know where the syntax is wrong and is this the right way
use javascript code for withparam function instead of server side code // JScript File function withparam(x) { var y = x + 10; return y; } function Button1_onclick() { var st = withparam(10); document.write(st); alert(st); } call Button1_onclick in OnClientClick
winnie
-
use javascript code for withparam function instead of server side code // JScript File function withparam(x) { var y = x + 10; return y; } function Button1_onclick() { var st = withparam(10); document.write(st); alert(st); } call Button1_onclick in OnClientClick
winnie
Yes, the withparam is the actual function to be called, i mean if we don't need any server side processing then this way would be the best.