views:

1437

answers:

3

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?

+4  A: 

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.

Arnis L.
i have done that and in the <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnableTheming="True" EnablePageMethods="true">pagemethods are true and it still doesnt work
kevinw
the Bottom line is the serverside method
kevinw
@kevinw updated my post a bit...
Arnis L.
thank you for all your help on this
kevinw
Thanks for that great feeling when you help to someone. :)
Arnis L.
+1  A: 

Client =/= Server

Look into Asynchronous Javascript and XML.

Charlie Somerville
+1  A: 

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

geoff
This will fail, cause public static methods knows nothing about viewstate => gridview.
Arnis L.
You're right about viewstate but the question is just about calling a server side method - nothing to do with viewstate. Obviously server side events can't be directly called with javascript.
geoff
this seems to have woked thank you however i am now running out of stack space
kevinw
do i need to enable viewstates?
kevinw
What are you trying to do in the server side method?
geoff
the server side method access's our database to get all of the info that is stored in the record selected for editing and also then populates a RadCalendar control to inform the user that they have x days available for booking a selected job from the grid
kevinw
I think an easier way of doing this would be to use Teleriks built in AJAX. http://www.telerik.com/help/aspnet-ajax/ajxajaxmanager.htmlOr consider using update panels as suggested by Arnis L.
geoff
thanks i have gone down the update panel route and am now sorting the issue out that way thank you for your help on this
kevinw
Just be careful with update panel. It can ruin performance a lot if used incorrectly. :)
Arnis L.