第一次单击时未触发按钮单击事件

本文关键字:单击 按钮 事件 第一次 | 更新日期: 2023-09-27 18:10:42

我有一个项目,其中事件需要在第一次点击时被触发但事件不是在第一次点击时被触发,而是在第二次点击时被触发但在第一次点击时确实发生了回发但事件没有被触发

<asp:Button ID="btn_search" runat="server" Text="Search" CssClass="button blue"  onclick="btn_search_Click"  CausesValidation="False"/>

按钮点击事件的cs代码

protected void btn_search_Click(object sender, EventArgs e)
{
    if (txt_subcategory.Text.Length != 0 && txt_category.Text.Length == 0 && txt_author.Text.Length == 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length == 0 && txt_edition.Text.Length == 0)
    {
        btnsearchsubcat();
        txt_subcategory.Text = "";
    }
    else if (txt_subcategory.Text.Length == 0 && txt_category.Text.Length != 0 && txt_author.Text.Length == 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length == 0 && txt_edition.Text.Length == 0)
    {
        btnsearchcat();
        txt_category.Text = "";
    }
    else if (txt_subcategory.Text.Length == 0 && txt_category.Text.Length == 0 && txt_author.Text.Length != 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length == 0 && txt_edition.Text.Length == 0)
    {
        btnsearchauthor();
        txt_author.Text = "";
    }
    else if (txt_subcategory.Text.Length == 0 && txt_category.Text.Length == 0 && txt_author.Text.Length == 0 && txt_publisher.Text.Length != 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length == 0 && txt_edition.Text.Length == 0)
    {
        btnsearchpublisher();
        txt_publisher.Text = "";
    }
    else if (txt_subcategory.Text.Length == 0 && txt_category.Text.Length == 0 && txt_author.Text.Length == 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length != 0 && txt_bookname.Text.Length == 0 && txt_edition.Text.Length == 0)
    {
        btnsearchisbn();
        txt_isbn.Text = "";
    }
    else if (txt_subcategory.Text.Length != 0 && txt_category.Text.Length == 0 && txt_author.Text.Length == 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length != 0 && txt_edition.Text.Length == 0)
    {
        btnsearchname();
        txt_bookname.Text = "";
    }
    else if (txt_subcategory.Text.Length != 0 && txt_category.Text.Length != 0 && txt_author.Text.Length == 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length == 0 && txt_edition.Text.Length == 0)
    {
        btnsearchcatsubcat();
    }
    else if (txt_subcategory.Text.Length != 0 && txt_category.Text.Length != 0 && txt_author.Text.Length != 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length == 0 && txt_edition.Text.Length == 0)
    {
        btnsearchcatsubcatauthor();
    }
    else if (txt_subcategory.Text.Length == 0 && txt_category.Text.Length == 0 && txt_author.Text.Length == 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length != 0 && txt_edition.Text.Length != 0)
    {
        btnsearchbooknameedition();
    }
    else if (txt_subcategory.Text.Length != 0 && txt_category.Text.Length == 0 && txt_author.Text.Length != 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length == 0 && txt_edition.Text.Length == 0)
    {
        btnsearchsubcatauthor();
    }
    else if (txt_subcategory.Text.Length != 0 && txt_category.Text.Length == 0 && txt_author.Text.Length == 0 && txt_publisher.Text.Length != 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length == 0 && txt_edition.Text.Length == 0)
    {
        fillgridsubcatpublisher();
    }
    else if (txt_subcategory.Text.Length == 0 && txt_category.Text.Length == 0 && txt_author.Text.Length == 0 && txt_publisher.Text.Length == 0 && txt_isbn.Text.Length == 0 && txt_bookname.Text.Length != 0 && txt_edition.Text.Length == 0)
    {
        btnsearchname();
    }
    else
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(),
        Guid.NewGuid().ToString
        (), "<script language=JavaScript>alert('Fill The TextBox ');</script>");
    }
}

第一次单击时未触发按钮单击事件

尝试:1.在配置文件

中设置
 <System.web><pages eventvalidation="true"/></system.web>

2看看ValidationGroup,你可能需要设置正确的值

但这些是你的问题的版本