1 Replies - 34490 Views - Last Post: 10 November 2009 - 12:46 PM Rate Topic: -----

#1 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

PageMethods is not defined [RESOLVED]

Posted 10 November 2009 - 12:02 PM

Ok, I'm working on calling C# methods from Javascript (just something I'm trying as I lay here) (I will explain what I've done, then show some code):

On the page I have added a ScriptManager (AJAX) and added EnablePageMethods="true" to enable page methods for my page, in my code behind I have this method (static, as for this to work they need to be static)

[System.Web.Services.WebMethod]
public static string GenerateLoginName()
{
	//return a dummy string until get working
	return "ABCD";
}



In my Javascript file I have the following 3 functions (one that calls GenerateLoginName and the success anf fail functions)

function GetLoginName(dest) 
{
	// call server side method
	PageMethods.GenerateLoginName(Success, Failed, dest);
}

// set the destination textbox value with the login name
function Success(result, ctrl) 
{
	var dest = DOMCall(ctrl);
	dest.value = result;
}

// alert message on some failure
function Failed(res, destCtrl) 
{
	alert(res.get_message());
}



Also, in the code behind I have this in the load event

GenerateLogin.Attributes.Add("onclick", "GetLoginName('" + LoginNameAutoGenerated.ClientID + "');");



But when I click that button I get

Quote

PageMethods is not defined


Anyone seen this or know how to resolve it?

Is This A Good Question/Topic? 0
  • +

Replies To: PageMethods is not defined [RESOLVED]

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: PageMethods is not defined [RESOLVED]

Posted 10 November 2009 - 12:46 PM

I'm a n00b, I added EnablePageMethods="true" to the wrong page :blush:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1