Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2007, 10:57 AM
Registered User
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating run time controls,

Hi All,

I want to create some runtime controls, and this is the code i had written in .cs file.

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            TextBox newTextBox = new TextBox();
            newTextBox.Text = "new Text Box";
            newTextBox.ID = "newTextBox";
            newTextBox.Visible = true;
         }
    }

i debugged the code and it executes properly,but i m unable to see my controls in runtime, please tell me where i m wrong or i need to do some thing else.


Creating run time controls,

Thanks and regards
Manish
 
Old February 10th, 2007, 04:11 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

TO see them at run-time, you need to add them to your page somehow. Right now, all you do is create an in-memory control.

To see the controls, try this:

1. Add a panel to the page. Let's say it's called Panel1.

2. Add the controls to the Controls collection of the panel:

Panel1.Controls.Add(newTextBox);

Now you control should be visible on the page.

Instead of Panels, you could use other container-like controls as well.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Controls At Run-Time robbev567 ASP.NET 2.0 Basics 2 July 25th, 2007 04:57 AM
Create Controls in Run Time Fredu Access 3 January 8th, 2005 10:03 AM
Copying controls at run time aspadda Excel VBA 0 November 12th, 2003 01:07 PM
Adding controls at run-time !! kishore_peddi C# 0 October 13th, 2003 06:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.