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

J

James Wong

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
 
S

Steven Cheng[MSFT]

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
 
J

James Wong

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
 
S

Steven Cheng[MSFT]

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
 
J

James Wong

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top