【问题标题】:How to get control values and modify them in Page Methods?如何在页面方法中获取控制值并修改它们?
【发布时间】:2010-10-05 13:07:29
【问题描述】:

我在页面中有几个控件。我需要在 Page 方法中修改这些值。我怎样才能做到这一点?。当我在页面方法中修改这些值时,应该反映在页面中吗?

请给我一个例子。

【问题讨论】:

  • “页面方法”是什么意思?您的控件是 .NET 控件还是 HTML?
  • 你说的页面方法,是指Web服务与AJAX集成的PageMethods选项,还是什么?

标签: c# asp.net jquery pagemethods


【解决方案1】:

快速示例:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    相关资源
    最近更新 更多