onclick事件在asp.net上不起作用

onclick event not working asp.net

本文关键字:不起作用 net asp 事件 onclick      更新时间:2023-09-26

嗨,朋友们,我有这个按钮,它的按钮点击不起作用

<asp:Button ID="btnfirstnext" runat="server" Text="Next" class="next1 action-button" OnClick="btnfirstnext_Click" OnClientClick="return false;" />

在这里,我使用类似的JavaScript

$(".next1").click(function () {
            if (animating) return true;
            animating = true;
            current_fs = $(this).parent();
            next_fs = $(this).parent().next();
            //activate next step on progressbar using the index of next_fs
            $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
            //show the next fieldset
            next_fs.show();
            //hide the current fieldset with style
            current_fs.animate({ opacity: 0 }, {
                step: function (now, mx) {
                    //as the opacity of current_fs reduces to 0 - stored in "now"
                    //1. scale current_fs down to 80%
                    scale = 1 - (1 - now) * 0.2;
                    //2. bring next_fs from the right(50%)
                    left = (now * 50) + "%";
                    //3. increase opacity of next_fs to 1 as it moves in
                    opacity = 1 - now;
                    current_fs.css({ 'transform': 'scale(' + scale + ')' });
                    next_fs.css({ 'left': left, 'opacity': opacity });
                },
                duration: 800,
                complete: function () {
                    current_fs.hide();
                    animating = false;
                },
                //this comes from the custom easing plugin
                easing: 'easeInOutBack'
              // $('btnfirstnext').trigger('click');
            });
        });

我想在按钮点击事件上运行一些代码,比如

protected void btnfirstnext_Click(object sender, EventArgs e)
    {
        lblmessage.text="Hello this button click working";
    }

在这里,您可以看到上面的详细信息,当我加载此代码时,它只运行JavaScript,而不运行按钮点击事件。这个JavaScript是用于一个弹出窗口的。请帮我摆脱困境。

请删除aspx中的OnClientClick="return false;"部分。我怀疑这是在阻止回邮。

您从OnClientClick返回false,如果从OnClientClick javascript事件处理程序返回false,那么您将无法返回post-如果您总是需要回发,则可以始终返回true。否则,您可以有条件地返回true或false。

仅使用您拥有的jQuery click事件处理程序并删除On OnClientClick

试试这个:

$(document).ready(function(){
  $(".next1").click(function () {
   //Your Code here

  });
});

并将其移除:OnClientClick="return false;"

您需要在asp:Button中删除OnClientClick="return false;"。它正在阻止您的回发。你的按钮需要看起来像这样:

<asp:Button ID="btnfirstnext" runat="server" Text="Next" class="next1 action-button" OnClick="btnfirstnext_Click" />

我将仅使用click事件处理程序来处理此问题。我还想添加document ready部分:

$(document).ready(function() {
     $(".next1").click(function() {
          // Add the rest of your code
     });
});

我希望这能有所帮助。

<asp:Button ID="btnfirstnext" runat="server" Text="Next" class="next1 action-button" OnClick="btnfirstnext_Click"; />

您必须删除OnClientClick="return false;"。