kevinw
kevinw

Reputation: 103

How do I call a serverside function from javascript?

I have a javascript function from where I am trying to call the serverside function WebSchedule.Client.RadGrid1_SelectedIndexChanged. This is the code:

<script type="text/javascript">

     function RowSelected(sender, args) 
     {
         var dataKeyValue = args.getDataKeyValue("Order_No");
         document.getElementById("txtOrderno").value = dataKeyValue;
         WebSchedule.Client.RadGrid1_SelectedIndexChanged(sender, args);
     }
 </script>

However, I get an error "WebSchedule is undefined". What am I doing wrong?

Upvotes: 2

Views: 7638

Answers (3)

user47322
user47322

Reputation:

Client =/= Server

Look into Asynchronous Javascript and XML.

Upvotes: 1

Arnis Lapsa
Arnis Lapsa

Reputation: 47567

Check out so called page methods.

Btw, is this supposed to be server side method or client side?

function RowSelected(sender, args) { 
    var dataKeyValue = args.getDataKeyValue("Order_No");      
    document.getElementById("txtOrderno").value = dataKeyValue;
    WebSchedule.Client.RadGrid1_SelectedIndexChanged(sender, args); 
} 

So - seems to me that's a javascript function.

As far as i understand, RadScriptManager inherits from System.Web.UI.ScriptManager. This is what EnablePageMethods prop does: "Gets or sets a value that indicates whether public static page methods in an ASP.NET page can be called from client script."

Those words in bold means - you won't see any control in that serverside method cause of lack of viewstate.

Therefore - consider using Update Panel control (i've got no ideas how it goes together with telerik controls) or make sure that your serverside method is completely stateless (pass needed data through javascript function).

Anyway - seems to me that you should investigate nature of page methods closer.

Upvotes: 4

Geoff Appleford
Geoff Appleford

Reputation: 18832

Your server side pagemethods must have the WebMethod attribute and be declared public static.

Then using javascript they can be called using this syntax: PageMethods.MethodName()

Upvotes: 1

Related Questions