1、有一个click按钮:
private void Button1_Click(object sender, System.EventArgs e)
{
语句1
语句2
语句3
} 想要语句2那里执行Page_Load函数(就是打开网页首要执行的那个默认函数): private void Page_Load(object sender, System.EventArgs e)
{
语句 }
我这样写不行:
private void Button1_Click(object sender, System.EventArgs e)
{
语句1
Page_Load();
语句3
} 请问该如何写才可以在语句2的地方执行Page_Load函数???
2、有一个click按钮:
private void Button1_Click(object sender, System.EventArgs e)
{
语句1
语句2
语句3
} 在点击按钮button1的时候,就先执行了Page_Load函数,然后再执行语句1,语句2,语句3,
请问有什么办法可以跳过Page_Load函数,不执行Page_Load函数。
就是说,点击button1的时候,就执行语句1-》语句2-》语句3。 谢谢
private void Button1_Click(object sender, System.EventArgs e)
{
语句1
语句2
语句3
} 想要语句2那里执行Page_Load函数(就是打开网页首要执行的那个默认函数): private void Page_Load(object sender, System.EventArgs e)
{
语句 }
我这样写不行:
private void Button1_Click(object sender, System.EventArgs e)
{
语句1
Page_Load();
语句3
} 请问该如何写才可以在语句2的地方执行Page_Load函数???
2、有一个click按钮:
private void Button1_Click(object sender, System.EventArgs e)
{
语句1
语句2
语句3
} 在点击按钮button1的时候,就先执行了Page_Load函数,然后再执行语句1,语句2,语句3,
请问有什么办法可以跳过Page_Load函数,不执行Page_Load函数。
就是说,点击button1的时候,就执行语句1-》语句2-》语句3。 谢谢
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
//Page_Load中的语句
}
}
{
if(this.IsPostBack) return;
//以下非PostBack时加载的代码
}
第二个问题,把Page_Load中的语句放在
if(!IsPostBack)
{
语句
}中
IsPostBack是判断这个页面是否是一个回发页面,页面第一次加载的时候,会执行if里的语句,点按钮的时候,这个页面就是回发了,就不会再执行if里的语句了
请问该如何写才可以在语句2的地方执行Page_Load函数???
page_load()
{
if(!ispostback)
{
load();
}
}
void load()
{
//your code here
}
void Button1_Click()
{
//语句1
load();
//语句3
}
void Button2_Click()
{
//语句1
//语句2
//语句3
}