Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have these objects:
  • txtb1 top: 150px left:450px
  • txtb2 top: 270px left:450px
  • txtb3 top: 390px left:450px

I want to align these objects vertically and that it is inside the lPaneln Panel.
C#
Myglobal.txtb1.Attributes.Add("style", "position: absolute;");
Myglobal.txtb1.Attributes.Add("style", "top: 150px;");
Myglobal.txtb1.Attributes.Add("style", "left:450px;");


What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;



public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var tbutton1 = new System.Web.UI.WebControls.Button();

        this.Boton1.Controls.Add(tbutton1);

        tbutton1.Click += new EventHandler(tbutton1_Click);


        tbutton1.Width = 80;
        tbutton1.Height = 30;
        tbutton1.Text = "BUTTON";
        tbutton1.Visible = true;

        _Default.bLabel ltitle = new _Default.bLabel();


        ltitle.ID = "Label1";
        ltitle.Text = "MY  PROJECT";


        iLabel.Controls.Add(ltitle);
        ltitle.Visible = true;

        _Default.bPanelpn lPaneln = new _Default.bPanelpn();

        iPanel.Controls.Add(lPaneln);
        iPanel.Visible = true;


        _Default.bTextbox txtb1 = new _Default.bTextbox();
        _Default.bTextbox txtb2 = new _Default.bTextbox();
        _Default.bTextbox txtb3 = new _Default.bTextbox();



        lPaneln.Controls.Add(txtb1);



        //static **
        //relative **
        //fixed **
        //absolute **
        //sticky



        string vposition = "static";

        txtb1.Style["position"] = vposition;
        txtb1.Style["top"] = "50px";
        txtb1.Style["left"] = "50px";


        //txtb1.Attributes.Add("style", "position: absolute;");
        //txtb1.Attributes.Add("style", "top: 150px;");
        //txtb1.Attributes.Add("style", "left:450px;");


        txtb1.Text = "DATA1";

        lPaneln.Controls.Add(txtb2);


        //txtb2.Attributes.Add("style", "position: absolute;");
        //txtb2.Attributes.Add("style", "top: 270px;");
        //txtb2.Attributes.Add("style", "left: 450px;");

        txtb2.Style["position"] = vposition;
        txtb2.Style["top"] = "100px";
        txtb2.Style["left"] = "50px";


        txtb2.Text = "DATA2";


        //txtb3.Attributes.Add("style", "position: absolute;");
        //txtb3.Attributes.Add("style", "top: 390px;");
        //txtb3.Attributes.Add("style", "left:450px;");


        txtb2.Style["position"] = vposition;

    
        txtb3.Text = "DATA3";

        lPaneln.Controls.Add(txtb3);

    }



    private void tbutton1_Click(object sender, EventArgs e)
    {
        
        
    }

    public class bPanelpn : Panel
    {
        public bPanelpn()
        {

            this.BorderStyle = BorderStyle.Double;
            this.ScrollBars = ScrollBars.Auto;
            this.Width = 500;
            this.Height = 200;
            this.BorderColor = System.Drawing.Color.Black;

        }
    }

    public bPanelpn lPaneln
    {
        get; private set;


    }


    public class bLabel : Label
    {
        public bLabel()
        {
            this.Style["Width"] = "275px";
            this.BorderStyle = BorderStyle.Double;
            this.Style["text-align"] = "center";
        }
    }

    public class bTextbox : TextBox
    {
        public bTextbox()
        {
            this.BackColor = System.Drawing.Color.White;
            this.BorderColor = System.Drawing.Color.Blue;
            this.Width = 80;
            this.Height = 20;


        }
    }



    public bTextbox txtb
    {
        get; private set;
    }

}


HTML
<!DOCTYPE html>
<head runat="server">
    <title></title>
</head>
<body>
    <style>
    .Csstxtb {
        border:2px solid;
        height: 12px;
        width:  56px; 
        border-color: rgba(0, 0, 0, 1);
    }
    .center {
      margin-left: auto;
      margin-right: auto;
      width: 21%;
      /*border: 3px solid green;*/
      /* border: hidden;a*/
      padding: 10px;
    }
    .center2 {
      margin-left: auto;
      margin-right: auto;
      width: 37%;
      /*border: 3px solid green;*/
      /* border: hidden;a*/
      padding: 10px;
    }
    .center3 {
      margin: 100px auto 0px 623px;
      
      width: 0%;
      /* border: hidden;a*/
      padding: 0px;
     }
    .center4 {
      margin-left: auto;
      margin-right: auto;
      width: 8%;
      /* border: hidden;a*/
      padding: 10px;
    }
    .centerTable { 
       margin: 0px auto;
    }
    </style>
    
    <form id="form1" runat="server">
        
         <br />
         <br />          
         <div class="center" id="iLabel" runat="server"></div>
         <br />          
         <div class="center2" id="iPanel" runat="server"></div>
         <br />
         <br />  
         <br />
         <div class="center4" id="Boton1" runat="server"></div>

    </form>
</body>
</html>
Posted
Updated 3-Jun-20 11:51am
v6
Comments
Richard Deeming 3-Jun-20 11:44am    
static variables and ASP.NET don't mix. Storing a control or page instance in a static variable is always the wrong thing to do.

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