在UpdatePanel控件失去价值 [英] Control in UpdatePanel loses value

查看:194
本文介绍了在UpdatePanel控件失去价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个组合框,第一个触发器的UpdatePanel,更新第二个:

 保护无效cb1_SelectedIndexChanged(对象发件人,EventArgs的发送)
        {        cb2.DataSource = DT1;
        cb2.DataBind();
         }

问题是,当我点击按钮,所有值都行,除了一个在UpdatePanel的,所以在UpdatePanel的子控件以某种方式重置选定的索引。

不知道如何解决这个问题?

我知道会话,但我不知道什么步骤CB2的值赋给会话。

感谢。

更新,ASPX

 < ASP:的UpdatePanel ID =UpdatePanel1=服务器ChildrenAsTriggers =FALSE
                                                        的UpdateMode =条件>
    < D​​X:ASPxComboBox ID =CB2=服务器HEIGHT =的22pxValueField =ID
                                                                值类型=System.Int32WIDTH =170像素>
                                                                <柱体和GT;
                                                                    < D​​X:ListBoxColumn标题=ID字段名=ID可见=FALSE/>
                                                                    < D​​X:ListBoxColumn标题=城市字段名=城市/>
                                                                < /专栏>
                                                            < / DX:ASPxComboBox>
< /&的ContentTemplate GT;
                                                    <&触发器GT;
                                                        < ASP:AsyncPostBackTrigger
    控件ID =CB1事件名称=的SelectedIndexChanged/>
                                                        < /触发器>
                                                    < / ASP:的UpdatePanel>


解决方案

一对夫妇的事情在这里:你有 ChildrenAsTriggers =FALSE,但你们又异步回传trigeer对孩子的控制:CB2。我想你应该的删除的的 ChildrenAsTriggers =FALSE属性(true是默认值),你可能是指有ansync回传trigeer设置为'CB1'控制象下面这样:

 < ASP:的UpdatePanel ID =UpdatePanel1=服务器的UpdateMode =条件>
    <&的ContentTemplate GT;
      < D​​X:ASPxComboBox ID =CB2=服务器HEIGHT =的22pxValueField =ID
                       值类型=System.Int32WIDTH =170像素>
        <柱体和GT;
           < D​​X:ListBoxColumn标题=ID字段名=ID可见=FALSE/>
           < D​​X:ListBoxColumn标题=城市字段名=城市/>
        < /专栏>
    < / DX:ASPxComboBox>
   < /&的ContentTemplate GT;
   <&触发器GT;
     < ASP:AsyncPostBackTrigger控件ID =CB1事件名称=的SelectedIndexChanged/>
   < /触发器>
  < / ASP:的UpdatePanel>

此外我认为你原来的code复制失踪开幕<的ContentTemplate方式> 标签

在这一点上你的CB1控件的事件`cb1_SelectedIndexChanged'应该解雇,并能够在更新上述的UpdatePanel的CB2控件的数据源。

I have two comboboxes, first one triggers updatepanel that updates second one:

        protected void cb1_SelectedIndexChanged(object sender, EventArgs e)
        {

        cb2.DataSource = DT1;
        cb2.DataBind();


         }

Problem is, when I click button, all values are ok, except one in UpdatePanel, so updatepanel somehow resets selected index on child controls.

Any idea how to fix this?

I know about sessions, but I don't know on what step to assign value of cb2 to session.

Thanks.

Update, aspx

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" 
                                                        UpdateMode="Conditional">
    <dx:ASPxComboBox ID="cb2" runat="server" Height="22px" ValueField="ID" 
                                                                ValueType="System.Int32" Width="170px">
                                                                <Columns>
                                                                    <dx:ListBoxColumn Caption="ID" FieldName="ID" Visible="False" />
                                                                    <dx:ListBoxColumn Caption="City" FieldName="City" />
                                                                </Columns>
                                                            </dx:ASPxComboBox>
</ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger
    ControlID="cb1" EventName="SelectedIndexChanged" />
                                                        </Triggers>
                                                    </asp:UpdatePanel>

解决方案

A couple of things here: you have ChildrenAsTriggers="False", but yet you have an async postback trigeer for a child control: 'cb2'. I think you should remove the ChildrenAsTriggers="False" property ("true" is default value) and you probably meant to have the ansync postback trigeer set to the `cb1' control like below:

   <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
    <ContentTemplate>
      <dx:ASPxComboBox ID="cb2" runat="server" Height="22px" ValueField="ID"     
                       ValueType="System.Int32" Width="170px">  
        <Columns>
           <dx:ListBoxColumn Caption="ID" FieldName="ID" Visible="False" /> 
           <dx:ListBoxColumn Caption="City" FieldName="City" /> 
        </Columns>                                                             
    </dx:ASPxComboBox> 
   </ContentTemplate>                                                     
   <Triggers>                                                         
     <asp:AsyncPostBackTrigger ControlID="cb1" EventName="SelectedIndexChanged" />   
   </Triggers>                                                     
  </asp:UpdatePanel>

Also I think your original code copied was missing the opening <ContentTemplate> tag.

At this point your cb1 control's event `cb1_SelectedIndexChanged' should fire and be able to update the cb2 control's datasource in the UpdatePanel above.

这篇关于在UpdatePanel控件失去价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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