This is a migrated thread and some comments may be shown as answers.

Calling a function on the server and returning a value

5 Answers 62 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Ed Staffin
Top achievements
Rank 1
Ed Staffin asked on 09 Feb 2009, 04:15 PM
Hi,
It seems like this should be possible, but I'm not seeing any examples.
All I want to do is, in javascript on teh client side make a call somehting like:

var myReturnValue = SomeCallToTheServer(SomeArgument);

Where SomeCallToTheSever is a server side function something like:

Public Function SomeCallToTheServer(arg as Object) as Int32
    return SomeValue
End Function

Any guidance and pointers to an example would be fantastic.
Thanks ... Ed

5 Answers, 1 is accepted

Sort by
0
SamJ
Top achievements
Rank 1
answered on 10 Feb 2009, 06:33 AM
Hi Ed,

Try the below suggestion:

<script type="text/javascript"
function MyClientFunction() 
    var myReturnValue = "<%= SomeCallToTheServer(arguments) %>"
</script> 

You also might need to wrap the sclient script in a RadCodeBlock.

I hope this helps you.


0
Ed Staffin
Top achievements
Rank 1
answered on 10 Feb 2009, 12:46 PM
Hi,
Thanks for the reply, but I don't think that will work. In your example, the arguments parameter is the problem. I need to pass a parameter from the client.
Thanks ... Ed
0
SamJ
Top achievements
Rank 1
answered on 10 Feb 2009, 02:39 PM
Hi Ed,

Yes, you are right. But tell me what do you need to pass as an argument and how would be this used on the server?

Thanks,
SamJ
0
Ed Staffin
Top achievements
Rank 1
answered on 10 Feb 2009, 03:00 PM
Hi,

I have a situation where I have an Id on the client and I want ot look up a name to go iwth it so I want to pass the id to the server and get the name back.
Thanks ... Ed
0
SamJ
Top achievements
Rank 1
answered on 10 Feb 2009, 03:48 PM
HI,

hmm... I understand your idea but I am not sure how this could be done.
What comes into my mind is to use hidden field, e.g. set the ID to the hidden field on the client and use its value on the server.
Tags
Ajax
Asked by
Ed Staffin
Top achievements
Rank 1
Answers by
SamJ
Top achievements
Rank 1
Ed Staffin
Top achievements
Rank 1
Share this question
or