从静态方法访问服务器端方法/控件
我有以下静态方法...我想从此方法更改服务器端标签的值..
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法使用 jQuery 调用服务器端代码。您可以调用Web服务,但它们不会影响您的页面,或者您可以将aspx页面加载到div中,这可以返回脚本来修改标签,但您不能像您所要求的那样只调用服务器方法。
如果您详细解释一下为什么要这样做,那么可能会有解决方法。例如,您可以使用 jQuery 更改标签的文本,但这一切都必须在客户端完成。例如...
这可能是更改标签文本的正确代码,但有一些方法可以确保您获得正确的 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...
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.