更新Panel渲染表行错误

发布于 2024-07-13 16:03:02 字数 949 浏览 6 评论 0原文

当我的 asp.net AJAX 更新面板更新时,我遇到了一个问题,它在我的表格顶部呈现内容,而不是在我的代码所属的位置:

<tr>
   <td>
   </td>
   <td>
      <asp:CheckBox ID="ddCheckbox" runat="server" Text="Checkbox"
           AutoPostBack="true" OnCheckedChanged="ddCheckboxChanged" />
   </td>
</tr>

    <asp:UpdatePanel ID="uxUpdatePanel" runat="server" RenderMode="Inline" UpdateMode="Conditional">
       <ContentTemplate>
          <tr>
             <td>
               Some Field:
             </td>
              <td>
                 <asp:TextBox ID="ddSomeField" runat="server" />
              </td>
            </tr>
          </ContentTemplate>
          <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddCheckbox" EventName="CheckedChanged" />
          </Triggers>
    </asp:UpdatePanel>

在我的服务器端事件中,我只是启用/禁用文本框。

I am having an issue when my asp.net AJAX Update Panel updates it renders the contents at the top of my table rather than in the place it belongs below is my code:

<tr>
   <td>
   </td>
   <td>
      <asp:CheckBox ID="ddCheckbox" runat="server" Text="Checkbox"
           AutoPostBack="true" OnCheckedChanged="ddCheckboxChanged" />
   </td>
</tr>

    <asp:UpdatePanel ID="uxUpdatePanel" runat="server" RenderMode="Inline" UpdateMode="Conditional">
       <ContentTemplate>
          <tr>
             <td>
               Some Field:
             </td>
              <td>
                 <asp:TextBox ID="ddSomeField" runat="server" />
              </td>
            </tr>
          </ContentTemplate>
          <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ddCheckbox" EventName="CheckedChanged" />
          </Triggers>
    </asp:UpdatePanel>

In my server side event I am just enabling/disabling the textbox.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

黯然#的苍凉 2024-07-20 16:03:02

1)创建自定义 updatepanel 控件(从 SingingEels 复制/粘贴)

2)使用此自定义具有属性 RenderedElement="TBODY" 的 updatepanel 控件

3) 嵌套表格,如下所示:

<TABLE>
  <TR>
    <TD>outside updatepanel</TD>
  </TR>
  <SingingEels:SemanticUpdatePanel ID="myUpdatePanel" runat="server" RenderedElement="TBODY">
    <ContentTemplate>
      <TR>
        <TD>inside updatepanel - 1th row</TD>
      </TR>
      <TR>
        <TD>inside updatepanel - 2nd row</TD>
      </TR>
      <TR>
        <TD>inside updatepanel - last row</TD>
      </TR>
    </ContentTemplate>
  </SingingEels:SemanticUpdatePanel>
  <TR>
    <TD>outside updatepanel</TD>
  </TR>
</TABLE>

1) create a custom updatepanel control ( copy/paste from SingingEels )

2) use this custom updatepanel control with an attribute RenderedElement="TBODY"

3) nest your table as follow:

<TABLE>
  <TR>
    <TD>outside updatepanel</TD>
  </TR>
  <SingingEels:SemanticUpdatePanel ID="myUpdatePanel" runat="server" RenderedElement="TBODY">
    <ContentTemplate>
      <TR>
        <TD>inside updatepanel - 1th row</TD>
      </TR>
      <TR>
        <TD>inside updatepanel - 2nd row</TD>
      </TR>
      <TR>
        <TD>inside updatepanel - last row</TD>
      </TR>
    </ContentTemplate>
  </SingingEels:SemanticUpdatePanel>
  <TR>
    <TD>outside updatepanel</TD>
  </TR>
</TABLE>
梦情居士 2024-07-20 16:03:02

我相信这是由于您嵌套更新面板的方式所致。 如果您将更新面板更改为 td 的子级,而不是表的子级:

<tr>
  <td>
    Some Field:
  </td>
  <td>
    <asp:UpdatePanel ID="uxUpdatePanel" runat="server" RenderMode="Inline" UpdateMode="Conditional">
       <ContentTemplate>
         <asp:TextBox ID="ddSomeField" runat="server" />
       </ContentTemplate>
       <Triggers>
          <asp:AsyncPostBackTrigger ControlID="ddCheckbox" EventName="CheckedChanged" />
       </Triggers>
    </asp:UpdatePanel>
   </td>
 </tr>

您应该全部修复。

I believe it's due to how you are nesting the Update panel. If you change the update panel to be a child of the td, rather than of the table:

<tr>
  <td>
    Some Field:
  </td>
  <td>
    <asp:UpdatePanel ID="uxUpdatePanel" runat="server" RenderMode="Inline" UpdateMode="Conditional">
       <ContentTemplate>
         <asp:TextBox ID="ddSomeField" runat="server" />
       </ContentTemplate>
       <Triggers>
          <asp:AsyncPostBackTrigger ControlID="ddCheckbox" EventName="CheckedChanged" />
       </Triggers>
    </asp:UpdatePanel>
   </td>
 </tr>

You should be all fixed up.

清引 2024-07-20 16:03:02

您是否已完成查看源代码以确认它确实在 HTML 本身内的该位置呈现它? 如果表格格式不正确,浏览器有时会在表格外部呈现标签。 它可能看起来在 HTML 本身中被正确定义,但缺少结束标记等可能会导致它以这种方式呈现。

Have you done a view source to confirm that it is actually rendering it in that location within the HTML itself? Browsers will sometimes render tags outside of the table if the table is malformed. It may appear to be defined properly in the HTML itself, but a missing closing tag etc may cause it to render that way.

可爱咩 2024-07-20 16:03:02

当更新面板回发到服务器时,它会回发所有内容(包括视图状态)。 为什么不直接做一些简单的 JavaScript 呢? 这会更有效率。

When the Update Panel posts back to the server, it posts everything back (including viewstate). Why not just do some simple javascript? It would be much more efficient.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文