Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

When i call method from javascript it is not run.
what is a problem?
this line : not work Load_Date()

C#
var str = Course_ApproveCourse.Load_Data('abc');

error : 'Course_ApproveCourse' is undefined


c#:
C#
protected void Page_Load(object sender, EventArgs e)
{       
   AjaxPro.Utility.RegisterTypeForAjax(typeof(Course_ApproveCourse), this.Page);//AJAX Method Registration
   ClientScript.RegisterClientScriptBlock(this.GetType(), "Message", "fnApproveSettings();", true);
}
AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.Read)]
public string Load_Data(string TestApproveId)
{
   if ((dstcourse.Tables[0].Rows[0][0].ToString() == "0") || (dstModuleLevelInfo.Tables[0].Rows[0][0].ToString() == "0"))
   {
      if (dstcourse.Tables[0].Rows[0][0].ToString() == "0")
      {
         str.Append("CourseApprove").Append(colSeperator);
      }
      else if (dstModuleLevelInfo.Tables[0].Rows[0][0].ToString() == "0")
      {
         str.Append("CourseLevelApprove").Append(colSeperator);
      }
   }
   return str.ToString();
}

jquery:
Java
function fnApproveSettings() {
   debugger;
   var str = Course_ApproveCourse.Load_Data('abc');
   alert(str);
   var strvalues = str.value.split(String.fromCharCode(195));
   if (strvalues[1] == "CourseApprove")
      $("#lblApprove")[0].innerHTML = "Module value approve ";
   else if (strvalues[1] == "CourseLevelApprove")
      $("#lblApprove")[0].innerHTML = "Module Level value approve ";
   $("#dialog-form").dialog("open");
}
Posted
Updated 12-May-14 22:49pm
v5

The problem is that

JavaScript
var str = Course_ApproveCourse.Load_Data('abc');


Isn't defined as a method in JavaScript. I've not used AjaxPro, but it looks like it could be one of a few things, this looks your most likely solution:
http://stackoverflow.com/questions/2715515/asp-net-2-0-c-sharp-ajaxpro-registertypeforajax[^] - you need to prefix the Course_ApproveCourse with the namespace of the Course_ApproveCourse asp page. The other thing is that (I assume) AJAXPro generates an on-the-fly JavaScript that contains this method - this could be missing?

One a separate note - I suggest you download a tool called "Fiddler" - it lets you see what is passed up and down the wire on each call. I am not affiliated with fiddler, telerik or any of it's partners, at least not as far as I'm aware :)
 
Share this answer
 
You need to create a "false" aspx page (which will never be called by a user). Here you define the method to be called as a webmethod (a webservice as it may), Then you can use json to call the webmethod with the correct parameters.

There are some tutorials and sample code on google...

Hope this helps.
 
Share this answer
 
Your C# method can not be called directly from javascript,because they are executed on Server Side.
You can either create a page and provide method on page load. and then call page using javascript.
or
use web service
 
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