简体   繁体   中英

Why all contents are aligned left within a content template in an update panel?

If I write dummy text in the 2 labels before the update timer starts, one appears at the right and the other appears at the left as expected However, when the updateTimer gets into picture both texts appear on the left stuck to each other

here's the code

 <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>

The TimedPanel is rendering as a span , like this:

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

Change your ContentTemplate to:

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

And add some CSS to align the LinkButton to the right:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM