How to set position of a web control depending on other control's position at run-time?

Discussion in 'ASP .Net Web Controls' started by James Wong, Jul 13, 2004.

  1. James Wong

    James Wong Guest

    Dear all,

    Take the simple example of my case: There're two label controls and the
    contents are assigned dynamically. I want to put the second one on the
    right-hand-side of the first one without any gap between them. Since I
    don't set the width property of both controls at design phrase to make them
    "AutoSize" enable and avoid word-wrap, I can't get the width of the first
    control to determine "position-should-be" of the second one at run-time.

    Though somebody has designed a complicated method to calculate the actual
    width of a string according to text content as well as font size, I found
    that the size represented for label control is "small, medium, large, etc"
    instead of the actual point / pixel size. I don't know how to convert
    something like "small" to point / pixel size to start the calculation.

    Does anybody have good idea to manage my problem? Thanks for your attention
    and kindly help!

    Regards,
    James Wong
    James Wong, Jul 13, 2004
    #1
    1. Advertising

  2. Hi James,

    From your description, you want to put two ASP.NET Label controls one by
    one in a single line and also make them close to each other with out
    additional space between them, yes>?

    As for such problem, I'll always recommand that we consider using
    serverside code to measure the text's length and set TextBox's length in
    the end( if we haven't any other choice) :).

    I think we can use a <table><tr><td>...</td></tr></table> tag around the
    two Label controls to workaround the problem. For example:
    <table>
    <tr>
    <td>
    <asp:Label ID="lblLeft" Runat="server"></asp:Label>
    <asp:Label ID="lblRight" Runat="server"></asp:Label>
    </td>
    </tr>
    </table>

    then, the <table><tr> will make the two labels(in fact is <span> element)
    in a single line. And since we haven't set the <table> 's width, it'll
    adjust its width as less as possible so that it exactly fit the width of
    the two Labels' together width.
    How do you think of this?


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Jul 13, 2004
    #2
    1. Advertising

  3. James Wong

    James Wong Guest

    Hi Steven,

    Thanks again for your reply! I've tried your idea to solve my problem and
    it works fine. However, I still think this should be considered as
    workaround only since it's quite strange to use a table to manage label's
    issue.

    Regards,
    James Wong

    "Steven Cheng[MSFT]" <> ¦b¶l¥ó
    news: ¤¤¼¶¼g...
    > Hi James,
    >
    > From your description, you want to put two ASP.NET Label controls one by
    > one in a single line and also make them close to each other with out
    > additional space between them, yes>?
    >
    > As for such problem, I'll always recommand that we consider using
    > serverside code to measure the text's length and set TextBox's length in
    > the end( if we haven't any other choice) :).
    >
    > I think we can use a <table><tr><td>...</td></tr></table> tag around the
    > two Label controls to workaround the problem. For example:
    > <table>
    > <tr>
    > <td>
    > <asp:Label ID="lblLeft" Runat="server"></asp:Label>
    > <asp:Label ID="lblRight" Runat="server"></asp:Label>
    > </td>
    > </tr>
    > </table>
    >
    > then, the <table><tr> will make the two labels(in fact is <span> element)
    > in a single line. And since we haven't set the <table> 's width, it'll
    > adjust its width as less as possible so that it exactly fit the width of
    > the two Labels' together width.
    > How do you think of this?
    >
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    > Get Preview at ASP.NET whidbey
    > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    >
    >
    James Wong, Jul 13, 2004
    #3
  4. Hi James,

    Thanks for your followup. As for the <table><tr><td>... </td></tr></table>
    approach, it is just one means to do it. And this is very commonly used in
    WebPage layout design that we use Html <table> element to structure our
    page. Also, we can use any other elements for formating text element such
    as <p > .dsfsdfdskfksdjf..........</p> and if you're familiar with the CSS
    style , that'll provide much more help on this. For example'
    <p style="....">
    some text here
    </p>

    And the VS.NET IDE support the intellisense for editing css style. Also,
    you can find many web resources on applying css styles which is widely used
    in web page layout design.
    Thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Jul 14, 2004
    #4
  5. James Wong

    James Wong Guest

    Hi Steven,

    Thanks for your additional information! I'm too fresh in web application
    development and there're a lot to learn.

    Regards,
    James Wong

    "Steven Cheng[MSFT]" <> ¦b¶l¥ó
    news: ¤¤¼¶¼g...
    > Hi James,
    >
    > Thanks for your followup. As for the <table><tr><td>...

    </td></tr></table>
    > approach, it is just one means to do it. And this is very commonly used in
    > WebPage layout design that we use Html <table> element to structure our
    > page. Also, we can use any other elements for formating text element such
    > as <p > .dsfsdfdskfksdjf..........</p> and if you're familiar with the CSS
    > style , that'll provide much more help on this. For example'
    > <p style="....">
    > some text here
    > </p>
    >
    > And the VS.NET IDE support the intellisense for editing css style. Also,
    > you can find many web resources on applying css styles which is widely

    used
    > in web page layout design.
    > Thanks.
    >
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    > Get Preview at ASP.NET whidbey
    > http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    >
    James Wong, Jul 14, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    475
  2. Replies:
    1
    Views:
    265
    Eric Theil
    Oct 20, 2006
  3. namo
    Replies:
    2
    Views:
    306
  4. Pierre Yves
    Replies:
    2
    Views:
    469
    Pierre Yves
    Jan 10, 2008
  5. Ethan
    Replies:
    3
    Views:
    322
    Ethan
    Jul 3, 2003
Loading...

Share This Page