0

I need to call server side code "c# Function" in my asp.net project in javascript so i used this way:

<script type="text/javascript">

    function doReadPublicData() {
        PageMethods.btnVerifyPubData_Click(OnGetMessageSuccess, OnGetMessageFailure);
    }

    function OnGetMessageSuccess(result, userContext, methodName) {
        alert(result);
    }

    function OnGetMessageFailure(error, userContext, methodName) {
        alert(error.get_message());
    }
</script>

And I enabled the EnablePageMethods property in the script manager:

<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
</asp:ScriptManager>

<asp:Button ID="btnVerifyPubData" runat="server" OnClientClick="doReadPublicData();"
    OnClick="btnVerifyPubData_Click" Text="Show Information"
    CssClass="submitButton" PostBackUrl="~/ParsePublicData.aspx" />

But this error occurs.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Belal_G
  • 75
  • 1
  • 2
  • 10
  • Not sure what you are up to here - you click a button and call a bit of javascript that clicks the button? Anyway, PageMethods are designed to access WebMethods. Your call to whatever function you want to run should be decorated with [System.Web.Services.WebMethod][System.WEb.Script.Services.ScriptMethod] – Martin Smellworse Aug 09 '14 at 14:42

1 Answers1

2

solved finally .. I have to add "static" to my web method to work successfully ! :

[WebMethod]
    public static void btnVerifyPubData_Jscript(string t)
    {

    }
Belal_G
  • 75
  • 1
  • 2
  • 10