如何更新 WebMethod 中的多个标签 (Asp:net / Ajax)

发布于 2024-08-11 11:35:53 字数 208 浏览 4 评论 0原文

我有大约 20 个标签需要更新。

考虑到性能和padeload-weight,我选择WebMethods来实现它(比updatepanel +计时器小得多)。

那么,如何更新WebMethod中的大量值呢?

(我的第一个意图是像我一样正常访问它们:lbl1.Text =“1”;lbl2.Text =“2”......但该方法是静态的 - 没有机会)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

方觉久 2024-08-18 11:35:53

创建类似的方法(选择一些更方便的名称:-))。

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

然后用 JavaScript 来完成,就像

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

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

“啊,好吧,这样你就可以开始了”。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文