473,289 Members | 1,840 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,289 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 1096
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.