开发者

How to update multiple labels in an WebMethod (Asp:net / Ajax)

开发者_如何学编程

I have around 20 labels to update.

In relation to performance and padeload-weight, I choose WebMethods to realize it (Much smaller then updatepanel + timer).

So, how to update a lot of values in the WebMethod?

(My First intention was to access them normaly as I do: lbl1.Text = "1"; lbl2.Text = "2".... but the method is static - no chance).


Create your method something like (choose some more convenient names tho :-)).

public static object MyMethod()
{
    return new {
        Value1 = "Label1Value",
        Value2 = "Label2Value",
        ...
    };
}

And do it in JavaScript like

<script type="text/javascript">
     var myObj = PageMethods.MyMethod();

     document.getElementById('<%=Label1.ID%>').innerHTML = myObj.Value1;
     document.getElementById('<%=Label2.ID%>').innerHTML = myObj.Value2;
     ...
</script>

Ah well, that'd get you started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜