简体   繁体   中英

Button click event not fired on first click

I have a project in which the event need to be fired on first click but the event is not getting fired on first click,it gets fired on second click but on first click postback do take place but event not getting fired

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

cs code for button click event

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>");
    }
}

Try: 1.set in congif file

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

2 take a look at ValidationGroup may be you need set correct value

But these as versions of your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM