473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

asp.net - beginner - why can't my class create controls on my page?

Hi,

My goal is to have a class named class1 that will render a label
control on whatever page needs it. I want to instantiate class1 from
whatever page, and then call the createLabel() method defined in
class1.

My ultimate goal is to use this structure as a template for adding
dropdownlists (but I want to understand a simple example first).

In the following basic code, the code compiles but I cannot get the
label to display on the web page. I don't want to touch the design
view and I want to do it all in code.
Any suggestions are greatly appreciated.
---------------
class1.cs
----------------
namespace Lefantze
{
using...
public class Class1: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label label1;
public Class1()
{
}
public void createLabel()
{
label1 = new Label();
label1.EnableViewState = true;
this.Controls.Add(label1); <-- I tried this
base.Controls.Add(label1); <-- I tried this
label1.Text = "This is from Class1, createLabel()";
}
}
}

--------------
default2.aspx.cs
--------------
using.....
using Lefantze;

public partial class Default2: Class1
{
protected void Page_Load(object sender, EventArgs e)
{
Class1 rangy = new Class1();
rangy.createLabel();
}
}
Thanks!

May 16 '06 #1
1 1098
rjl
I want to do the same. you have to add at least the declaration on one
line in asp page. also, I have better luck adding the control to a
panel object for placement.

May 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Raghuraman | last post by:
Hai ! I use the Grid control with the data environment and the recordset control by dragging from the data env. But if i run the page alone in the iexplorer it tells the error like pm.script...
5
by: Steve | last post by:
Visual Studio 2003 .Net / C# I have a 2 page Tab Control for users to add a Job in my application. The first page is for them to choose which type of Job they would like. The type of Job...
0
by: suzy | last post by:
i have managed to get page templates working by creating a template.cs file with the following code. i hope this is the best way?!?! public class BasePage : Page { protected override void...
8
by: Smkmdb1 | last post by:
Hi everyone, I'm a student of ASP.net. Being an ex Perl/CGI programmer who made extra cash making scripts and selling them on the web, I was wondering if one typically uses this format with...
5
by: Just Me | last post by:
Given a button name Btn_5 and Index=5 I want to do something like dim zz as string = Btn_??Index??.Text or given an array of buttons, do:
13
by: Ranginald | last post by:
I am new to oop so please bear with me: Could someone please explain to me why the "protected void runCategory() method" cannot access the local ddlCategory object that is easily accessed in...
4
by: MikeB | last post by:
I've been all over the net with this question, I hope I've finally found a group where I can ask about Visual Basic 2005. I'm at uni and we're working with Visual Basic 2005. I have some books, ...
9
by: =?Utf-8?B?SGFyZHkgV2FuZw==?= | last post by:
Hi all, I followed first walk through sample from http://ajax.asp.net/docs/tutorials/IntroductionUpdatePanel.aspx to create my first testing page, The problem is after I clicked that botton, it...
12
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I'm doing a web app in VB/Dot Net 2.0. I'm probably a bit rusty and I have no experience using the repeater control. I have a user control I've created with multiple properties. I've created a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.