IsPostBack条件的作用是什么? [英] What is the effect of IsPostBack Condition?

查看:123
本文介绍了IsPostBack条件的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用AJAX的地方有一个aspx页面.像

I have a aspx Page where I am using AJAX. like

<asp:UpdatePanel runat="server" ID="upPanelDDLProgram">
  <ContentTemplate>
    <asp:DropDownList ID="DDLProgram" runat="server" Width="194px" Height="18px" OnSelectedIndexChanged="OnDDLProgramChanged" AutoPostBack="true">
    </asp:DropDownList>
  </ContentTemplate>
</asp:UpdatePanel> 

我后面的代码就像

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsPostBack)
        //{
        //    BindProgramDDL();
        //}
        BindProgramDDL();
    }

    protected void BindProgramDDL()
    {
        List<CcProgramEntity> programEntities = FormSaleSubmit_BAO.GetAllPrograms();

        DDLProgram.DataSource = programEntities;
        DDLProgram.DataTextField = "Shortname";
        DDLProgram.DataValueField = "Id";
        DDLProgram.DataBind();
        string programCode = programEntities[DDLProgram.SelectedIndex].Code;
    }

    protected void OnDDLProgramChanged(object sender, EventArgs e)
    {
        List<CcProgramEntity> programEntities = FormSaleSubmit_BAO.GetAllPrograms();
        string programCode = programEntities[DDLProgram.SelectedIndex].Code;
    }

如果条件是页面加载事件,则将其注释掉.如果我切换页面加载事件的注释部分,则在两种情况下都可以正常工作.我的问题是为什么会如此?

the If condition is the page load event, is commented out. If I toggle the comment part of the page load event, it works perfect in both cases. My question is why is this heppening?

推荐答案

如果我对您没错....

If I am getting you correct .......

DropDown列表中包含数据,即使您在发回邮件后第二次不绑定它时也是如此.......... 因为它具有服务器端控件,并且每个服务器端控件都具有其视图状态多数民众赞成在不删除数据的情况下.

DropDown list has data even you are not binding it second time after post back..........its becasuse its server side control and each serverside control has its view state with it thats y its not removing data.

IsPostBack -在使用服务器端控件(如下拉菜单,复选框,文本框)进行回发时为true,则在首次加载页面时,此属性为为false,但在随后的请求中,此属性的相同页面值为true.您可以查看msdn文档以获取有关它的更多详细信息.

IsPostBack - it true when do the post back by using serverside control like dropdown, checkbox , textbox............When you load page first time this property is false but in subsequent request to same page value of this property is true. you can check msdn document for more detail about it.

这篇关于IsPostBack条件的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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