Search code examples
c#asp.netjquerypagemethods

How to get control values and modify them in Page Methods?


I have couple of controls in the page. I need to modify these value in Page method. How can I do that?. When I modify those values in page method should reflect in page?

Please give me expample.


Solution

  • Quick example:

    <asp:ScriptManager runat="server" EnablePageMethods="true" />
    <!-- or ToolkitScriptManager, but remember to put only one -->
    
    <script type="text/javascript">
        function invokeMethod() {
            x = document.getElementById('<%= TextBox1.ClientID %>').value;
            PageMethods.theMethod(x, OnSuccess, OnFailure);
        }
        function OnSuccess(r) {
            document.getElementById('<%= TextBox1.ClientID %>').value = r;
        }
        function OnFailure(r) {
            alert(r._message);
        }
    </script>
    

        [System.Web.Services.WebMethod()]
        public static string theMethod(string x)
        {
            return x + "!!!";
        }