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 April 16th, 2008, 03:47 AM
Registered User
 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add textbox in cs file

hi
 i copied these codes from "Wrox-Professional Web Parts and Custom Controls with ASP.NET" to my cs.File
protected override void CreateChildControls()
    {
        base.CreateChildControls();
        //LiteralControl=represent html elements,html and other strings in asp.net page that don't requared procesing on the server
        LiteralControl lt;
        System.Web.UI.WebControls.TextBox txt = new TextBox();
        lt = new LiteralControl("<b>Value: ");
        this.Controls.Add(lt);

        txt.Text = "Hello,world";
        txt.ID = "txtInput";
        this.Controls.Add(txt);

        lt = new LiteralControl("</b>");
        this.Controls.Add(txt);
}
but , i saw this error:
Control 'txtInput' of type 'TextBox' must be placed inside a form tag with runat=server


Why?

 
Old April 25th, 2008, 02:23 AM
Registered User
 
Join Date: Apr 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

These are the steps to make you learn that how can you add run time controls with different values.

First when You created
 lt = new LiteralControl("<b>Value: "); means you are instantiating a new literal control

Second
 lt = new LiteralControl("</b>");
        this.Controls.Add(txt);
is to show you that you can change values dynamically

If you want to add another literal control then declare another object name such as
Literal Control obj = new literal COntrol();
obj.text="&lt value";


Thanks
neha
 
Old April 30th, 2008, 02:37 PM
Authorized User
 
Join Date: Jun 2007
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hericles
Default

You may have simply missed out the <form runat=server> tag as well. That error message means the controls you have placed on the page aren't wrapped between <form runat=server> and </form> tags. ASP.Net controls need the runat=server element to function properly if they are to run on the server rather than the client.

Steve

"I will prepare and one day my chance will come."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Keyboard shortcut to go from cs to aspx file roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 June 20th, 2008 01:28 PM
how to call .cs file into another application ravi_bachwala ASP.NET 1.0 and 1.1 Basics 0 June 19th, 2007 07:30 AM
SQL in .cs file the_dude ADO.NET 2 January 27th, 2007 04:37 AM
Page reference in cs file jacob ASP.NET 1.0 and 1.1 Basics 1 July 22nd, 2003 10:37 PM





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