2013-04-23 155 views
0

我有一个项目需要在第一次点击时触发事件,但事件并未在第一次点击时被触发,它在第二次点击时被触发,但在第一次点击后发送地方,但事件不被解雇按钮点击事件没有在第一次点击时触发

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

[这个答案可能会帮助(http://stackoverflow.com/a/2784140/187697 ) – keyboardP 2013-04-23 11:52:39

+0

你确定你没有在表单的'Load'方法中做一些奇怪的事情吗?看,如果按钮在'Load'期间完全改变,它可以防止'Click'发射。 ASP.NET在**触发事件之前重建了表单服务器端**。 – 2013-04-23 12:26:50

+0

关注此链接(http://stackoverflow.com/questions/2765815/asp-net-button-event-handlers-do-not-fire-on-the-first-click-but-on-the-second ),它会引导你正确的方向。希望它对你有所帮助。 – Rahul 2013-04-23 11:53:24

回答

0

尝试: 1.设置在congif文件

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

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

但这些作为你的问题的版本

相关问题