我可以创建一个ASP.NET的ImageButton不回发? [英] Can I create an ASP.NET ImageButton that doesn't postback?

查看:137
本文介绍了我可以创建一个ASP.NET的ImageButton不回发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用仅客户端脚本执行ImageButton控件。我可以指定客户端脚本使用OnClientClick属性来执行,但我怎么从试图在用户每次点击它时后停止吗?没有理由单击此按钮时发布。我设置的CausesValidation为False,但这并不可以发布阻止它。

I'm trying to use the ImageButton control for client-side script execution only. I can specify the client-side script to execute using the OnClientClick property, but how do I stop it from trying to post every time the user clicks it? There is no reason to post when this button is clicked. I've set CausesValidation to False, but this doesn't stop it from posting.

推荐答案

下面是你可以做到这一点,而不与其他控件的回传功能冲突的一种方式:

Here's one way you could do it without conflicting with the postback functioning of other controls:

定义你的按钮是这样的:

Define your button something like this:

<asp:Button runat="server" Text="Button" UseSubmitBehavior="false" OnClientClick="alert('my client script here');my" />

我的中的处理程序的OnClientClick结束是一种方法,强制回发别名asp.net的__doPostBack客户端事件;我们只需无为类似于此脚本重写的行为:

The "my" ending in the handler for OnClientClick is a way to alias asp.net's __doPostBack client event that forces the postback; we simply override the behavior by doing nothing similar to this script:

<script type="text/javascript">

function my__doPostBack(eventTarget, eventArgument) {
    //Just swallow the click without postback of the form
}
</script>

编辑:Yeesh,我觉得我需要洗澡后,一些搞鬼,我需要为了得到asp.net做我想做什么,拉

Yeesh, I feel like I need to take a shower after some of the dirty tricks that I need to pull in order to get asp.net to do what I want.

这篇关于我可以创建一个ASP.NET的ImageButton不回发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆