Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi All,

I have a requirement where in a row I have 5 td and each td contain a button.
but I have to show few buttons in certain conditions.so how can I show the buttons in the center of the row.I mean want to arrange the buttons so that they will be centered.suppose two buttons are visible then it should be centered.

XML
<div>

        <table style="width: 100%">
            <tr>
                <td align="center">
                    <table>
                        <tr>
                            <td style="width: 20%" id="tda" runat="server">
                                <asp:Button ID="btnA" Text="A" runat="server" Width="100px" />
                            </td>
                            <td style="width:1px">
                            </td>
                            <td style="width: 20%" id="tdb" runat="server">
                                <asp:Button ID="ButtonB" Text="B" runat="server" Width="100px" />
                            </td>
                            <td style="width:1px">
                            </td>
                            <td style="width: 20%" id="tdc" runat="server">
                                <asp:Button ID="ButtonC" Text="C" runat="server" Width="100px" />
                            </td>
                            <td style="width:1px">
                            </td>
                            <td style="width: 20%" id="tdd" runat="server">
                                <asp:Button ID="ButtonD" Text="D" runat="server" Width="100px" />
                            </td>
                            <td style="width:1px">
                            </td>
                            <td style="width: 20%" id="tde" runat="server">
                                <asp:Button ID="ButtonE" Text="E" runat="server" Width="100px" />
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
            <td align="center">
            <asp:Button id="btnX" runat="server" Text="check" onclick="btnX_Click"/>
            </td>
            </tr>
        </table>

    </div>



And the code in my aspx file is as below

C#
protected void btnX_Click(object sender, EventArgs e)
        {
            //on certain conditions i want only tda and tde should be visible
            //but once i do this i get space between these two buttons
            tda.Visible = true;
            tdb.Visible = false;
            tdc.Visible = false;
            tdd.Visible = false;
            tde.Visible = true;



        }
Posted
Updated 3-Nov-13 10:22am
v2

You started working in a wrong way from the very beginning. Please stop using style and other formatting attributes in HTML, move it all to CSS.

Please see:
http://www.w3schools.com/css/css_align.asp[^],
http://www.w3schools.com/cssref/pr_text_text-align.asp[^],
http://www.w3.org/Style/Examples/007/center.en.html[^],
http://www.w3.org/TR/css3-align/[^].

Also, your requirement is not clear. Center relative to what? A row? If you have more then one element in a row, it's not possible, as it would mean that these elements would overlap at the center, which is not going to happen, unless you want to use absolute positioning (not recommended). Maybe, you have only one element per row, or you mean something else, such as centering relative to td. But don't clarify it yet. First, try to defined proper styles in a right way by yourself and ask another question if you really face a problem.

—SA
 
Share this answer
 
v2
Comments
PP from bangalore 3-Nov-13 16:53pm    
thanks for the reply. But the problem is how can I arrange the visible tds or buttons so that ther wont be any space . Actually when I make the tds visible false or true then the invisible tds also take the sacing between the buttons. as shown in the code. As tda and tde are visible but the tdb,tdcand tdd which are nothing but the ids if the td which is run at server attribute.can I make a feel that thereis no button in between the visible buttons. if all the buttons (tds ) are visible then ther is no problem for that case.
Sergey Alexandrovich Kryukov 3-Nov-13 18:14pm    
I would rather advise to review the design of it... Why doing so, what are the ultimate goals?
Don't you think you are trying to make it more complex than it has to be?
—SA
For positioning the button on the center you can use html center tag like this.

<center><input type="button" /></center>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900