Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to add labels dynamically to the asp.net website that is develop with c#.
But label is added it is not placed define top and left according to the code.I used to placeholders and forms 2,but itz not works.Could u plz help me

this is my code................

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
    <div>
    </div>
    </form>
</body>
</html>





==========================form load====================================
x is incremented according to the code......


Label l5 = new Label();
       l5.ID = "Label" + x;
       l5.Style["Top"] = "1361";
       l5.Style["Left"] = "8161";
       l5.Text = dt3.Rows[x]["DefoultText"].ToString();
       PlaceHolder1.Controls.Add(l5);

       Label l = new Label();
       l.ID = "Label" + x;
       l.Style["Top"] = "7261";
       l.Style["Left"] = "1381";
       l.Text = dt3.Rows[x]["DefoultText"].ToString();
       form1.Controls.Add(l);
Posted
Updated 16-Jul-11 23:42pm
v2

1 solution

You have two (actually three) problems.

1. You don't specify your units:
l5.Style["Top"] = "1361px";

or em or whatever

2. You need to set the position
labelId.Style["position"] = "relative";

where labelId = l, l5 etc. and relative is my best guess at the type of CSS positioning you want, YMMV.

3. Some of the co-ordinate numbers you are using are huge for a web page. A left of 8161px would imply your page is roughly more more than four screens wide for most users. I assume you are using these values to test, but there is a danger you will miss these labels when testing as they are so far off the screen without scrolling.
 
Share this answer
 
Comments
tkkf87 17-Jul-11 13:03pm    
thx bro it works,but i have another problem which i retrieve coordinates from previous system database that was created according to desktop application coordinates.Do u have solution to map older coordinates to web base system
Keith Barrow 17-Jul-11 16:35pm    
Glad my answer got you going again.
As for the mapping you just need to come up with a scaling factor (a standard figure to divide the desktop co-ordinate by) so the oringinal co-ordinates map to values within the normal bounds of your web page. You might also need to subtract an offset too, if the the desktop app starts at x=100 y = 50 for example, these need to be subtracted first.
tkkf87 19-Jul-11 10:26am    
Can you please give ma example

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