本文介绍了在默认页面中执行事件和在母版页中执行另一个事件时发生冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET Web表单项目,在主页面中我有一个按钮(searchButton),我在searchButton_Click事件中编写了一个代码,点击Go按钮后(如果用户在文本框中键入内容,按Enter键),用户将被重定向到另一个页面(FrmSearchResult.aspx)



  public   partial   class  Site1:System.Web.UI.MasterPage 
{
受保护 void Page_Load( object sender,EventArgs e)
{
}

protected void searchButton_Click( object sender,EventArgs e)
{
Session [ nameA] = s earchText.Text;
Response.Redirect( FrmSearchResult.aspx);
Session.RemoveAll();
}
}
}





我还有Default.aspx页面,其中提到了母版页!

在默认页面中我有一个文本框(searchUniTextBox),我在searchUniTextBox_ValueChanged事件中实现了一个代码!

  protected   void  searchUniTextBox_ValueChanged( object  sender,EventArgs e)
{
string searchUni = searchUniTextBox.Text.ToLower( );
string [] uniItem = new string [CheckBoxList1.Items.Count];
for int i = 0 ; i < CheckBoxList1.Items.Count; i ++)
{
if (CheckBoxList1.Items [i] .Text.ToLower()。Contains(searchUni))
CheckBoxList1.Items [i] .Selected = true ;
}
}



但问题是每当用户按下Enter键时,此事件(searchUniTextBox_ValueChanged)执行,并且紧接着那个searchButton_Click在主页面执行!!!!!

我不知道如何阻止在主页面中执行searchButton_Click事件,当searchUniTextBox_ValueChanged事件触发时?

谢谢你这么多

解决方案

I have a ASP.NET Web Form Project, in the master page I have a button(searchButton), I wrote a code in searchButton_Click event, after clicking on "Go" button (also if user types something in the textbox and press Enter key), user will be redirected to another page(FrmSearchResult.aspx)

    public partial class Site1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void searchButton_Click(object sender, EventArgs e)
        {
            Session["nameA"] = searchText.Text;
            Response.Redirect("FrmSearchResult.aspx");
            Session.RemoveAll();
        }
    }
}



I also have Default.aspx page which has mentioned master page!
In the default page I have a textbox (searchUniTextBox), and I implemented a code in searchUniTextBox_ValueChanged event!

protected void searchUniTextBox_ValueChanged(object sender, EventArgs e)
       {
           string searchUni = searchUniTextBox.Text.ToLower();
           string[] uniItem = new string[CheckBoxList1.Items.Count];
           for (int i = 0; i < CheckBoxList1.Items.Count; i++)
           {
               if (CheckBoxList1.Items[i].Text.ToLower().Contains(searchUni))
                   CheckBoxList1.Items[i].Selected = true;
           }
       }


But the problem is that whenever user presses Enter key, this event (searchUniTextBox_ValueChanged) executes, and immediately after that searchButton_Click in the master page executes!!!!!
I do not how I can prevent executing searchButton_Click event in the master page, when searchUniTextBox_ValueChanged event fires??
Thank you so much

解决方案


这篇关于在默认页面中执行事件和在母版页中执行另一个事件时发生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 22:12