C# 我可以在PageLoad事件之前调用dropdownlist selectedIndexchanged吗?
更改C# 我可以在PageLoad事件之前调用dropdownlist selectedIndexchanged吗?,c#,asp.net,C#,Asp.net,更改下拉列表中的值时selectedIndexchange应在PageLoad事件之前调用 如何在PageLoad事件之前调用dropdownlistselectedIndexchanged?根据ASP.NET生命周期
下拉列表中的值时
selectedIndexchange
应在PageLoad
事件之前调用
如何在
PageLoad
事件之前调用dropdownlist
selectedIndexchanged
?根据ASP.NET
生命周期
事件首先触发,然后触发其他控件
事件
但是,作为第一步,您可以通过从Page\u Load
事件处理代码手动调用SelectedIndexChanged
事件来触发dropDownList
SelectedIndexChanged
事件
试试这个:
protected void Page_Load(object sender, EventArgs e)
{
//call the DropDownList1 selectedindexchanged event manually
dropDownList1_SelectedIndexChanged(sender, e);
//page load event handling code
}
protected void dropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//DropDownList1 SelectedIndexChanged event handling code.
}
根据ASP.NET
生命周期
页面加载
事件将首先触发,然后触发其他控件
事件
但是,作为第一步,您可以通过从Page\u Load
事件处理代码手动调用SelectedIndexChanged
事件来触发dropDownList
SelectedIndexChanged
事件
试试这个:
protected void Page_Load(object sender, EventArgs e)
{
//call the DropDownList1 selectedindexchanged event manually
dropDownList1_SelectedIndexChanged(sender, e);
//page load event handling code
}
protected void dropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//DropDownList1 SelectedIndexChanged event handling code.
}
IHMO,首先搜索更多关于你的疑问,然后提出问题。现在,在深入asp之前,如果你能理解asp.NET页面Life cyce.IHMO,那就更好了。首先,搜索更多关于你的疑问,然后提出一个问题。现在,在进入asp之前,如果你能理解ASP.NET页面的生命周期,那就更好了。确保从页面加载中传递dropdownList1
而不是sender
,以避免dropdownList1\u SelectedIndexChanged
事件中潜在的强制转换错误。确保从Page\u加载
以避免在dropDownList1\u SelectedIndexChanged
事件中出现潜在的强制转换错误。