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
Вы уверены, что не делаете что-то странное в методе «Загрузить» формы? Смотрите, если бы кнопка вообще не менялась во время «загрузки», это могло бы предотвратить стрельбу «Click». ASP.NET восстанавливает форму на стороне сервера ** перед началом ** запуска. –
Следуйте за этим [Ссылка] (http://stackoverflow.com/questions/2765815/asp-net-button-event-handlers-do-not-fire-on-the-first-click-but-on-the-second), он будет направлять вас в правильном направлении. Надеюсь, это поможет вам. – Rahul