如何获取控件值并在页面方法中修改它们?

时间:2010-10-05 13:07:29

标签: c# asp.net jquery pagemethods

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

请给我示例。

1 个答案:

答案 0 :(得分: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 + "!!!";
    }