Monday, March 26, 2012

PageMethods is Undefined

HI,

its Urgent

I am Getting Same Error Could u please Help me Out..

Here is My Code..

using System.Web.UI.HtmlControls;

using System.Web.Services;

using Microsoft.Web.Script.Services;

using Microsoft.Web.Script;

[WebMethod]publicvoid GetNewMessage()

{

string str ="Hello";

Response.Write(str);

}

Javascript

PageMethods.GetNewMessage();

<asp:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true">

<Scripts>

<asp:ScriptReferencepath="scripts.js"/>

</Scripts>

</asp:ScriptManager>

Thanks in Advance,

Suman...

Please its Urgent...

this is not sufficient to debug your error ... you need to show us the whole thing ... and what kind of error is that? JavaScript or server error?


check this post out ... same error as yours:http://forums.asp.net/t/993893.aspx


ScriptManager has to have EnablePageMethods=true and the WebMethod has to be static.


hi here is my full code..

aspx file

<bodystyle="margin: 0px;padding: 0px;">

<formrunat="server"action="RF_Message.aspx">

<divid="ContentPanel">

<divid="MessageList">

<asp:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"EnablePageMethods="true"EnableScriptGlobalization="true"EnableScriptLocalization="true">

<%--<Scripts>

<asp:ScriptReference Path="scripts.js" />

</Scripts>--%>

</asp:ScriptManager>

</div>

</div>

</form>

</body>

</html>

<scriptlanguage="javascript"type="text/javascript">

var str = PageMethods.GetNewMessage();

alert(str);

var result = document.createElement("div");var divlist = el("MessageList");

result.innerHTML = str;

divlist.appendChild(result);

function el(id)

{

return document.getElementById(id);

}

</script>

aspx.cs file..

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Web.Services;

using System.Web.Script.Services;

using System.Web.Script;

publicpartialclassRF_Message : System.Web.UI.Page

{

//ChatManger Chatmanger = ChatManger.GetChatManager();

protectedvoid Page_Load(object sender,EventArgs e)

{

}

}

#region Script callback function

[System.Web.Services.WebMethod]

publicstaticstring GetNewMessage()

{

string str ="Hello";

return str;

}

#endregion

}

I am Getting Javascript Error While Running...

i am Getting alert Undefined...


RIght, you're executing that embedded script block as the page gets to it; pagemethods haven't been created yet (that happens during the clientside init, iirc. Try pulling all that code into your pageLoad() javascript function and see if that doens't help.

No comments:

Post a Comment