更新按钮标签

时间:2011-11-30 14:47:29

标签: c# asp.net-ajax

我有一个JavaScript函数用于aspx页面中的HTML按钮单击事件和页面代码隐藏中的服务器方法。当用户点击HTML按钮时,它将被处理,按钮将显示答案。

如何使用AJAX来更新按钮标签?

当我尝试在某处设置更新时,页面不会更新按钮。文本框更新工作正常。从下面的代码可以看出,btnDivide目前的设置值为“获取天气”,但我需要在用户完成处理后更改它。

<script type="text/javascript">
<![CDATA[

// This function creates an asynchronous call to the service
function makeCall(operation){
    var n1 = document.getElementById("num1").value;
    var n2 = document.getElementById("num2").value;


    // If user filled out these fields, call the service
    if(n1 && n2){

        // Instantiate a service proxy
        var proxy = new Service();

        // Call correct operation on vf cproxy       
        switch(operation){

            case "gridOne":
proxy.Calculate(AjaxService.Operation.getWeather,n1,n2,    
onSuccess, onFail, null);
                btnDivide.value = "TestNewValue";

                break;
            case "gridTwo":
*******
</script>

<style type="text/css">
    #result
    {
        width: 1010px;
    }
 </style>

</head>
<body>
<h1>Ajax TicTacToe</h1>
<p>Major City: <input type="text" id="num1" onclick="return 
num1_onclick()" /></p>
<p>Country: <input type="text" id="num2" onclick="return num2_onclick()"
 /></p> 
&nbsp;
<br />
<input id="btnDivide" type="button" onclick="return makeCall('gridOne');" 
    value="Get Weather" />

2 个答案:

答案 0 :(得分:2)

您需要endRequest事件的事件处理程序 看看这里:http://msdn.microsoft.com/en-us/library/bb383810.aspx

答案 1 :(得分:0)

 function onSuccess(mathResult){
    document.getElementById("result").value = mathResult;
    document.getElementById("btnDivide").value = "test";

}