1

I am creating ASP.NET wep page. I have a world map and I want to add some image buttons (cities) controls in C#. I made the method:

I am using stored procedure to get data from database but when I add next city to the procedure the previously added imagebutton changes its position.

private void LocateCities()
{
IDBManager dbManager = new DBManager(DataProvider.SqlServer);
dbManager.ConnectionString = @"Data Source=server; Initial Catalog=db;  Integrated Security = SSPI;";
try
{
    dbManager.Open();
    dbManager.CreateParameters(2);
    dbManager.AddParameters(0, "@Function", "All");
    dbManager.AddParameters(1, "@Team", "All");
    DataSet ds = new DataSet("Stuff");
    ds = dbManager.ExecuteDataSet(CommandType.StoredProcedure, "sp_select_staff_and_cities");                    

    foreach (DataRow dr in ds.Tables[0].Rows)
    {
        int xaxis = Convert.ToInt32(dr["xaxis"]) ;
        int yaxis = Convert.ToInt32(dr["yaxis"]) ;
        int textxaxis = xaxis + 30;
        int textyaxis = yaxis - 10;

        ImageButton btnCity = new ImageButton();
        btnCity.ImageUrl = "~/Images/cyanball1.gif";
        btnCity.Height = 10;
        btnCity.Attributes.Add("style", "Z-INDEX:100; POSITION:relative; left:" + xaxis + "px; TOP:" + yaxis + "px; Left:10px;Right:10px");

        Label lblCity = new Label();
        lblCity.Text = dr["city"].ToString();
        lblCity.Attributes.Add("style", "Z-INDEX: 100;POSITION:relative; left:" + textxaxis + "px; TOP:" + textyaxis + "px");

        PanelMap.Controls.Add(lblCity);
        PanelMap.Controls.Add(btnCity);    
    }
}
catch (Exception ex)
{
    Response.Write(ex.ToString());
}
finally
{
    dbManager.Dispose();
}
}

I am using panel to keep image with map: .PanelMap { width:960px; height:572px; text-align:left; }

What should be changed in above code to keep the points in its place?

I tried to use position:absolute but it cause that posiotion is derived relative to the page and I would like it would be derived relatively to the panel control.

3
  • you can wrap your image buttons and label in an html div. Get rid of the height and positioning stuff and it should just flow as you add elements to it. Commented Jun 10, 2013 at 23:07
  • Jay, could You please be more specific? Thank You in advance. Commented Jun 10, 2013 at 23:19
  • Basically remove your style attributes, remove the heigh specification on your panel and use System.Web.UI.HtmlControls.HtmlGenericControl("div") as a wrapper to your label and button Commented Jun 11, 2013 at 15:31

1 Answer 1

1

The problem would be this, POSITION:relative, so change that to POSITION:absolute on both lines and you'll be good.

Sign up to request clarification or add additional context in comments.

3 Comments

I used POSITION:absolute although I wanted do avoid this. Thaks.
I have another problem - when I use absolute posiotion and I have some hidden forms it doesn't work with each other because when hidden form appear the images buttons are not in correct place. Is there any way to repair this issue?
@user2027004, that sounds quite involved. Please post another question with that information -and be very detailed because now you're dealing with dynamic HTML and that's hard to debug online.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.