【问题标题】:Why all contents are aligned left within a content template in an update panel?为什么所有内容都在更新面板的内容模板中左对齐?
【发布时间】:2011-06-17 22:28:02
【问题描述】:

如果我在更新计时器开始之前在 2 个标签中写入虚拟文本,则一个出现在右侧,另一个出现在左侧 但是,当 updateTimer 进入图片时,两个文本都出现在左侧,彼此粘在一起

这是代码

 <table width="100%" border="0" cellspacing="7" cellpadding="0">
                                            <tr>
                                                <asp:ScriptManager ID="ScriptManager1" runat="server" />
                                                <asp:Timer runat="server" ID="UpdateTimer" Interval="5000" OnTick="UpdateTimer_Tick" />
                                                <asp:UpdatePanel runat="server" ID="TimedPanel" UpdateMode="Conditional" RenderMode="Inline">
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="UpdateTimer" EventName="Tick" />
                                                    </Triggers>
                                                    <ContentTemplate>
                                                        <td align="left">
                                                            <asp:Label ID="userNameLabel" runat="server"></asp:Label>
                                                        </td>

                                                        <td align="right">
                                                            <asp:LinkButton ID="userWebsiteLabel" runat="server"></asp:LinkButton>
                                                        </td>
                                                    </ContentTemplate>
                                                </asp:UpdatePanel>
                                            </tr>
                                        </table>

【问题讨论】:

  • 您要替换每个 Tick 上的文本吗?

标签: asp.net ajax contenttemplateselector


【解决方案1】:

TimedPanel 呈现为span,如下所示:

<span id="TimedPanel">
   <span id="userNameLabel">label</span>
   <a id="userWebsiteLabel" href="javascript:__doPostBack('userWebsiteLabel','')">linkbutton</a>
</span>

将您的 ContentTemplate 更改为:

<ContentTemplate>
   <asp:Label ID="userNameLabel" runat="server" Text="label" />
   <asp:LinkButton ID="userWebsiteLabel" runat="server" Text="linkbutton" />
</ContentTemplate>

并添加一些 CSS 以将 LinkButton 向右对齐:

<style type="text/css">
#TimedPanel a {float: right;}
</style>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-29
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多