ASP.Net 脚本控件,从 OnClick 和 FireFox 返回 False

发布于 2024-07-09 23:34:14 字数 1294 浏览 5 评论 0原文

简短说明:

我有一个脚本控件,它在脚本文件中处理单击事件。 Click 处理程序会弹出确认提示并返回提示的值。

问题:

IE 看​​到返回 False(在确认框中选择取消)并且没有回发。 Firefox 会忽略这一点并触发回发。

解决方案?:

我读到,如果我以旧时尚方式执行此操作,我需要:

onClick="return SomeMethod();"

在标记中。 希望有一种方法可以通过脚本控件来做到这一点吗?

示例:

这是我在脚本文件中的内容:

//THIS IS THE METHOD CLICK CALLS
handleLnkDeleteButtonClick: function(e)
{
    var confirmed = confirm('This will delete the current Message category and move all messages to the Oprhan cataegory.  Continue?');
    return confirmed;
},

initialize: function()
{
    this._lnkDeleteButton = $get(this._lnkDeleteButtonID);
    this._lnkDeleteButton.idpicker = this;

    //HOOK BEGINS HERE
    this._lnkDeleteButtonClick = Function.createDelegate(this, this.handleLnkDeleteButtonClick);
    $addHandler(this._lnkDeleteButton, "click", this._lnkDeleteButtonClick);
    //END HOOK HERE

    NDI.WebControls.Client.PersonalMessageTypePicker.callBaseMethod(this, 'initialize');
},

dispose: function()
{
    $removeHandler(this._lnkDeleteButton, "click", this._lnkDeleteButtonClick);
    NDI.WebControls.Client.PersonalMessageTypePicker.callBaseMethod(this, 'dispose');
}

Short Explanation:

I have a script control that has the click event being handled in the script file. The Click handler pops up a confirm prompt and returns the prompt's value.

Problem:

IE sees the return False (Cancel is selected on the confirm box) and there is no postback. Firefox ignores this and fires the postback.

Solution?:

I read that if I were doing this the old fashion way, I would need to have:

onClick="return SomeMethod();"

In the markup. There hopefully is a way to do this with script controls?

Example:

Here's what I have in the script file:

//THIS IS THE METHOD CLICK CALLS
handleLnkDeleteButtonClick: function(e)
{
    var confirmed = confirm('This will delete the current Message category and move all messages to the Oprhan cataegory.  Continue?');
    return confirmed;
},

initialize: function()
{
    this._lnkDeleteButton = $get(this._lnkDeleteButtonID);
    this._lnkDeleteButton.idpicker = this;

    //HOOK BEGINS HERE
    this._lnkDeleteButtonClick = Function.createDelegate(this, this.handleLnkDeleteButtonClick);
    $addHandler(this._lnkDeleteButton, "click", this._lnkDeleteButtonClick);
    //END HOOK HERE

    NDI.WebControls.Client.PersonalMessageTypePicker.callBaseMethod(this, 'initialize');
},

dispose: function()
{
    $removeHandler(this._lnkDeleteButton, "click", this._lnkDeleteButtonClick);
    NDI.WebControls.Client.PersonalMessageTypePicker.callBaseMethod(this, 'dispose');
}

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

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

发布评论

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

评论(1

魂牵梦绕锁你心扉 2024-07-16 23:34:14

好吧,在花了太多时间尝试为谷歌正确表达事物之后,我自己解决了这个问题。 原来有一个方法可以调用,这样你就不必担心返回 true 或 false。

handleLnkDeleteButtonClick: function(e)
{
    var confirmed = confirm('This will delete the currery Message category and move all messages to the Oprhan cataegory.  Allow?');
    if (!confirmed)
    {
        e.preventDefault();
    }
},

因此,我不必返回确认,而只需检查它的值并调用 e.preventDefault 方法来阻止点击触发。

Ok so solved it myself after about way too much time trying to phrase things correctly for google. Turns out there is a method to call so that you don't have to worry about returning true or false.

handleLnkDeleteButtonClick: function(e)
{
    var confirmed = confirm('This will delete the currery Message category and move all messages to the Oprhan cataegory.  Allow?');
    if (!confirmed)
    {
        e.preventDefault();
    }
},

So instead of returning confirmed, I merely had to check it's value and call the e.preventDefault method to stop the click from firing.

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