if(!Page.IsPostBack)的问题,请帮帮我。 [英] problem with if (!Page.IsPostBack), please help me out.

查看:134
本文介绍了if(!Page.IsPostBack)的问题,请帮帮我。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





if(!Page.IsPostBack)意味着:如果conditoin第一次和第二次它应该是假的,它应该工作,否则条件将被调用。对吗?



这是我的代码。



if (!Page.IsPostBack) means : it should work if conditoin first time and second time it should be false and else condition will invoke. right?

this my code.

protected void Page_Load(object sender, EventArgs e)
{

}
protected void treeview_clicked(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ModuleTreeView1.CollapseAll();
FillTreeView();
}
}



条件不调用。如果我这样给出(Page.IsPostBack),它会调用if条件,但第二次也会调用if。





注意:treevive_clicked是aspx页面中图像按钮上的onnclick事件。


It is not invoking if condition. if i give like this if (Page.IsPostBack), it invokes if condition but second time also it goes inside of if.


NOTE : treevive_clicked is onnclick event in image button in aspx page.

推荐答案

你好b $ b

这是一个很好的explenation我发现对于这个问题:

什么是回发?



Hi
Here is a nice explenation i found for the question:
What is a postback?

引用:

首次显示aspx页面时,会执行Page_Load事件中的任何代码,包括if(!IsPostBack)。当后续时间显示相同页面时,仅执行if(!IsPostBack)之外的代码。第二种情况发生在有一个button_click事件,它从服务器控件或页面的局部变量中读取一些值,并显示具有这些值的同一页面。



由于您单击树视图并且事件将触发:

When an aspx page is displayed for the first time, any code within the Page_Load event, including the if(!IsPostBack) is executed. When the same page is displayed in subsequent times, only the code outside the if(!IsPostBack) is executed. The second scenario happens when there is, say a button_click event, which reads some values either from a server control or a local variable of the page and displays the same page with these values.

Since you click on your treeview and event will trigger:

protected void treeview_clicked(object sender, EventArgs e)





在这里你可以编码知道你的树视图被点击的东西,所以你的



Here you can code things knowing your treeview was clicked, so your

if (!Page.IsPostBack)



这里没有意义。 (请删除它)


Doesn't really makes sense here. (Please delete it)





这只会在Page_Load事件中有意义。



希望这有帮助,

Bert



It would only make sense in the Page_Load event.

Hope this helped,
Bert


这篇关于if(!Page.IsPostBack)的问题,请帮帮我。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆