我们可以在asp.net的超链接contron上添加click事件吗? [英] can we add click event on the hyperlink contron in asp.net
问题描述
我想在点击事件的超链接上编写代码我们可以对超链接控件进行编译
+5 for Solution 1
另一种方法是使用 LinkButton
问候。
您可以使用客户端单击超链接。使用属性集合,如:
myHyperlink.Attributes.Add(onClick,alert('Hello'););
对于服务器端,类似的讨论在这里:
使用onClick覆盖默认超链接操作 [ ^ ]
需要一个超链接onclick事件来运行服务器端 [ ^ ]
在ASP.Net中,您可以将 onclick 事件附加到Hyperlink控件中两种方式。第一种方法是在设计时添加和分配值,方法是在HTML标记代码块中添加 onclick 属性作为 HyperLink 控件的属性。
< asp:HyperLink ID = HyperLink1
runat = server
NavigateUrl = Default2.aspx
onclick= 返回确认('你确定吗?'); >
超链接
< / asp:HyperLink >
第二种方法是以编程方式添加onclick属性at服务器端。
HyperLink1.Attributes.Add(onclick,返回确认('你确定要导航到其他页面吗?'););
在下面的示例中,javascript函数将显示确认消息,其中包含确定和取消按钮。如果用户单击取消按钮,则返回false,否则为真。
< script type = text / javascript >
函数confirmNavigation(){
return confirm('你确定要导航到其他页面吗?');
}
< / script >
< asp:HyperLink ID = HyperLink1
runat = server
NavigateUrl = Default2.aspx
onclick = 返回confirmNavigation(); >
超链接
< / asp:HyperLink > 跨度>
i want to write coding on the hyper link on click event can we castomise the hyperlink control
+5 for Solution 1
Another way is to use LinkButton
Regards.
You can use client side onclick of a hyperlink. Use Attributes collection as in:
myHyperlink.Attributes.Add ("onClick", "alert('Hello');");
For server side, similar discussions here:
Override default hyperlink action with onClick[^]
Need a hyperlink "onclick" event to run server-side[^]
In ASP.Net you can attach the onclick event to Hyperlink control in two ways. First way is to add and assign the value at the time of designing by adding the onclick property as an attribute of HyperLink control in the HTML markup code block.
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="Default2.aspx" onclick="return confirm('Are you sure?');"> Hyperlink </asp:HyperLink>
The Second way is to add the onclick attribute programmatically at the server side.
HyperLink1.Attributes.Add("onclick", "return confirm('Are you sure to navigate to other page?');");
In the example below a javascript function will show a confirm message with Ok and cancel button. If the user will click the cancel button then it will return false otherwise true.
<script type="text/javascript"> function confirmNavigation(){ return confirm('Are you sure to navigate to other page?'); } </script>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="Default2.aspx" onclick="return confirmNavigation();"> Hyperlink </asp:HyperLink>
这篇关于我们可以在asp.net的超链接contron上添加click事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!