This is not working for me asp.net web page. Maybe dumb question:

dim tex as new textbox

tex.location = new point (150,150)---------this is highlighted as error
tex.width = 150 ---------this does nothing
tex.height = 22 ---------this does nothing

controls.add(tex) ---------this is highlighted as error

Where is my textbox named tex?
Please let me know if you have solution for me.

Thanks

Dani AI

Generated

As notes, this thread belongs to Classic ASP while the question is about ASP.NET Web Forms. The root cause of the errors is treating a WebForms server control like a WinForms control. A WebForms TextBox does not have a WinForms-style Location property; layout and positioning are done with HTML/CSS. Also, when creating controls at runtime you must add them to a server-side container and do so at the correct point in the page lifecycle so they survive postbacks and wire events.

Example (C#) — create and add a TextBox in the Init phase and set placement via CSS:

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    var dyn = new System.Web.UI.WebControls.TextBox { ID = "dynText1" };
    dyn.Attributes["style"] = "position:absolute; left:150px; top:150px; width:150px; height:22px;";
    PlaceHolder1.Controls.Add(dyn);
}

Practical tips for :

  • Use a server container (PlaceHolder or Panel with runat="server") and call Controls.Add on that container.
  • Create and add dynamic controls in OnInit/Page_Init so viewstate and events work; recreate them on every postback.
  • For sizing you can use CSS or the server-side properties (for example Width = Unit.Pixel(150)); for positioning use CSS (position:absolute or layout with CSS classes).
  • If you actually need client-side dynamic insertion (no postback required), create elements with JavaScript instead.

Official references that explain the lifecycle and dynamic-control patterns: Microsoft Web Forms dynamic controls guide (), the ControlCollection.Add API (ControlCollection.Add), and CSS positioning basics (MDN: position).

It won't work here either because this forum is for Classic ASP and not ASP.Net

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.