Hii,
Well PageMethods have always been a controversial topic but I believe they will be called when you have an event attached to the control whihc you are using. In this case if you put a Javascript event such as 'onmouseover', then it works perfectly...
ex:
<script type="text/javascript">
function GetLabel() {
PageMethods.GetLabelText(onsuccess, onfailure);
}
function onsuccess(result) {
var x = document.getElementById('lblnew');
x.innerHTML = result;
}
function onfailure(error) {
alert(error);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label id="lblnew" onmouseover="GetLabel();"> hiii</label>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
</div>
</form>
</body>
</html>
aspx.cs:
[System.Web.Services.WebMethod]
public static string GetLabelText()
{
return "Dark Knight";
}
Calling a plain Javascript function won't work IMO because the label control doesnot know when to call it. Try like this and you will understand much stuffs.
Happy Coding...