Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 3rd, 2005, 05:21 AM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default need help in asp.net

I want to add the controls in a webform created in asp.net using vb.net as the choosen language.if i add label control programmatically , at run time , it works properly ; bt if i try to add textbox or button controls then it shows the error on the page .

the code that i'm writing is:----

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim btn As New Label
        btn.Text = "Click"
        btn.ID = "Button1"
        Me.Controls.Add(btn)

        Dim t1 As New TextBox
        Me.Controls.Add(t1)

    End Sub

the error it shows is :---

Server Error in '/WebApplication8' Application.
--------------------------------------------------------------------------------

Control '_ctl0' of type 'TextBox' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control '_ctl0' of type 'TextBox' must be placed inside a form tag with runat=server.




 
Old February 3rd, 2005, 09:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

It says you either:

Don't have a <form> tag with the attribute runat="server" declared

OR

The textbox declared with runat="server" is above the <form> element or below the </form> element.

Now that I think about it, adding the controls to the page may be causing that. It would be better to put an asp:Panel within the page, and add the controls to the panel instead.

Brian
 
Old February 3rd, 2005, 02:59 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

why do you need to add the controls dynamically?
 
Old February 8th, 2005, 04:19 AM
Registered User
 
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Try adding <form runat="server"> at runtime before you create the control.

Hope this will work






Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 3.5 answers in Professional ASP.NET 3.5 jminatel ASP.NET 3.5 Professionals 1 August 22nd, 2011 07:34 AM
Turning a regular ASP.NET App into an AJAX ASP.Net donrafeal7 Ajax 2 August 31st, 2007 12:33 AM
Database diagram in .net using asp.net,c#.net scotttiger ADO.NET 2 February 16th, 2005 01:35 AM





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