简体   繁体   English

使用window.location和asp.net Web窗体运行方法

[英]run method using window.location with asp.net web forms

是否可以为超链接设置服务器端单击处理程序?

It sounds like you're after ASP.net Web Methods, there's an example here . 这听起来像你ASP.net Web方法后,有一个例子在这里

Basically, you decorate a method in your code-behind with the System.Web.Script.Services.ScriptMethod and System.Web.Script.Services.WebMethod attributes, which means that you can then call the method from javascript. 基本上,您可以使用System.Web.Script.Services.ScriptMethodSystem.Web.Script.Services.WebMethod属性在代码后方装饰一个方法,这意味着您可以从javascript中调用该方法。

Consider converting your hyperlink, perhaps it's an <a> tag, to a ASP.NET server side control: LinkButton . 考虑将您的超链接(可能是<a>标记)转换为ASP.NET服务器端控件: LinkBut​​ton

<asp:LinkButton runat="server" id="foo"   OnClick="LinkButton_Click" 
     Text="Do Some Stuff Server Side, and Expect a Redirect Somewhere" />

It's not clear from the question what you'd like to do server side. 从这个问题尚不清楚您想在服务器端做什么。 From here, you can call custom code and basically do anything once it's posted back. 从这里,您可以调用自定义代码,并在将其回发后基本上可以执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM