带有asyncpostback触发器的UpdatePanel无法正常工作并导致奇怪的行为

问题描述 投票:1回答:1

这里发生了一些奇怪的事情。我目前有一个下拉drpIntervention有autopostback =“true”,直到现在我调用服务器代码,根据所选值的禁用/启用控件。我不喜欢回发闪烁,所以我试图用AsyncPostBack Trigger包装UpdatePanel中的代码,但奇怪的事情正在发生:

这是此更新面板的代码:

     <asp:UpdatePanel ID="UpdatePanel5" runat ="server" UpdateMode ="Conditional">
      <ContentTemplate >
        <tr>
         <td colspan="3" class="questionFont">
          <table style="width:100%; border-collapse:collapse ">
          <tr>
            <td>
              <b>a.&nbsp;What is the Problem?</b>
            </td>
            <td >
             <asp:DropDownList ID="drpCrisisType" runat="server" autopostback="true" Enabled ="false" OnSelectedIndexChanged="drpCrisisType_SelectedIndexChanged ">
             </asp:DropDownList>
             <span runat="server" style="font-size:12px;  font-family :'Times New Roman';" ID="Span16"><i>(Description)</i></span>
            </td>
         </tr>                                    
   </ContentTemplate>
       <Triggers>  
          <asp:AsyncPostBackTrigger ControlID="drpIntervention" EventName="SelectedIndexChanged" />
       </Triggers>
   </asp:UpdatePanel>

这是应该触发事件的按钮的代码,它位于updatePanel之外

  <tr>
     <td class="questionFont" style="padding-top: 20px">
       <b>4.&nbsp;Did you engage in any?</b>
     </td>
     <td style="padding-top: 20px">
        <asp:DropDownList ID="drpIntervention" runat="server" autopostback="true"  OnSelectedIndexChanged="drpIntervention_SelectedIndexChanged ">
        </asp:DropDownList>
     </td>
   </tr>

所以这不是我的整个代码,<tr>属于一个表,它上面有更多,这个更新面板和下拉只是它的一部分。发生的事情是,我在浏览器中加载页面并且一切看起来都不错,然后我在drpIntervention中选择一个值,并且更新面板中包含的内容(其他下拉列表以及具有启用/禁用服务器代码的文本框)被移动到其他位置以上页面中的内容。更奇怪的是,移动的内容在没有使用postback的情况下正常工作,但内容也在其原始位置,并且在那里不起作用。

我希望我有意义,只要我从drpIntervention中选择一个值,更新面板中的内容就会在页面上的两个位置。心灵爆炸!

asp.net updatepanel
1个回答
0
投票

我认为这个问题与我放置asp:update panel的地方有关。因为我把它放在表中,所以它以某种方式覆盖了格式并将更新面板中的内容放到了表的顶部。

解决这个问题的是当我为这个问题创建一个表格,并用asp:update panel包装整个表格。这解决了问题

© www.soinside.com 2019 - 2024. All rights reserved.