Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 16th, 2008, 04:47 AM
Registered User
 
Join Date: Apr 2008
Location: tehran, tehran, Iran.
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?

  #2 (permalink)  
Old April 25th, 2008, 03:23 AM
Registered User
 
Join Date: Apr 2008
Location: delhi, delhi, India.
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
  #3 (permalink)  
Old April 30th, 2008, 03:37 PM
Authorized User
 
Join Date: Jun 2007
Location: Christchurch, , New Zealand.
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."
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02:28 PM
how to call .cs file into another application ravi_bachwala ASP.NET 1.0 and 1.1 Basics 0 June 19th, 2007 08: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 11:37 PM



All times are GMT -4. The time now is 09:28 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.