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>");
}
}
[這個答案可能會幫助(http://stackoverflow.com/a/2784140/187697 ) – keyboardP 2013-04-23 11:52:39
你確定你沒有在表單的'Load'方法中做一些奇怪的事情嗎?看,如果按鈕在'Load'期間完全改變,它可以防止'Click'發射。 ASP.NET在**觸發事件之前重建了表單服務器端**。 – 2013-04-23 12:26:50
關注此鏈接(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