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

☆樱花仙子☆ 提交于 2019-12-25 19:04:18

问题


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.


回答1:


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 + "!!!";
    }


来源:https://stackoverflow.com/questions/3863898/how-to-get-control-values-and-modify-them-in-page-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!