Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have theis method to populate combobox

C#
 [WebMethod]
protected void getLecturesOnEdit()
        {
            int ss = Convert.ToInt32(txtEditlecturerNameHiden.Value);

            List<bl_User> lecturerList = new List<bl_User>();
            bl_User lecturer = new bl_User();
            lecturerList = lecturer.getLecturesList(ss);
            cboEditLecturer.DataSource = lecturerList;
            cboEditLecturer.DataTextField = "fullName";
            cboEditLecturer.DataValueField = "userID";
            cboEditLecturer.DataBind();}



Now this is how I call it from javascript
JavaScript
function onEditModule() {
 

    PageMethods.getLecturesOnEdit();


   


}


I get this error"PageMethods is not defined "
How can I call that c# method on javaScript?
Posted

Hey there,

Make sure you have this line on the page:
ASP.NET
<asp:scriptmanager id="ScriptManager1" runat="server" enablepagemethods="true"  />

and make your WebMethod public and static as suggested by Soumitra.
Moreover, it would be helpful if you post how you are calling your JavaScript function.

Hope it helps, let me know if it does or doesn't.

Good luck.

Azee...
 
Share this answer
 
v4
A web method has to be static and public. your method is not static.
please change your method and test it.
For more information,please check this article
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900