Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 953
kevinw Avatar asked May 26 '26 05:05

kevinw


2 Answers

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.

like image 90
Arnis Lapsa Avatar answered May 28 '26 17:05

Arnis Lapsa


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()

like image 37
Geoff Appleford Avatar answered May 28 '26 19:05

Geoff Appleford



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!