从静态方法访问服务器端方法/控件

发布于 2025-01-03 22:52:13 字数 236 浏览 1 评论 0原文

我有以下静态方法...我想从此方法更改服务器端标签的值..

Public Static void CallFromJquery()
{
Default1 page = (Default1)HttpContext.Current.CurrentHandler;
page.Label1.Text = "Hello";
}

请让我知道如何做到这一点..提前致谢:)

问候, 卡延

I have the below static method... i want to change the server side label's value from this method..

Public Static void CallFromJquery()
{
Default1 page = (Default1)HttpContext.Current.CurrentHandler;
page.Label1.Text = "Hello";
}

Please let me know how this can done.. thanks in advance :)

Regards,
Kalyan

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

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

发布评论

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

评论(1

落花随流水 2025-01-10 22:52:13

您无法使用 jQuery 调用服务器端代码。您可以调用Web服务,但它们不会影响您的页面,或者您可以将aspx页面加载到div中,这可以返回脚本来修改标签,但您不能像您所要求的那样只调用服务器方法。

如果您详细解释一下为什么要这样做,那么可能会有解决方法。例如,您可以使用 jQuery 更改标签的文本,但这一切都必须在客户端完成。例如...

$("#ctl00_MainContent_Label1").text("Hello world");

这可能是更改标签文本的正确代码,但有一些方法可以确保您获得正确的 ID。

如果您不只是寻找“这有效吗”的答案,请向我们提供更多信息,我们可能会提供帮助。

You can't call server-side code with jQuery. You can call web services, but they won't affect your page, or you could load an aspx page into a div and that could return script to modify the label, but you can't just call a server method like you've asked.

If you explain a little more about why you want to do it then there may be a workround. For example, you can change the text of the label with jQuery, but it must all be done client-side. For example...

$("#ctl00_MainContent_Label1").text("Hello world");

that's likely to be the correct code to change your label text, but there are ways to ensure that you get the correct ID.

If you're not just looking for an answer to "does this work", then give us more info and we can probably help.

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