473,407 Members | 2,359 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,407 software developers and data experts.

Can't access the server control from .cs code!

Trying to migrate from ASP... been scratching my head for almost 12 hours
now on this task that should be so easy, wtf can't I access the asp:label
control from my .cs code??? It returns no errors but simply no text is
inserted...
I have 3 pages;

*** default.aspx ***
<%@ Register TagPrefix="UserControls" TagName="Initializer"
Src="initializer.ascx" %>
<UserControls:Initializer runat="server" />

*** initializer.ascx ***
<%@ Control Src="initializer.cs" EnableViewState="False" %>
<asp:label id="myLabel" text="here I want the text" runat=server/>

*** initializer.cs ***
using System.Web.UI.WebControls;
public class Initializer
{
protected Label myLabel;
void Page_Load(object sender, System.EventArgs e)
{
Label myLabel = new Label();
myLabel.Text = "and I have success";
}
}
Nov 18 '05 #1
1 1217
"Davíð Þórisson" <db**@hi.is> wrote in message news:eK*************@tk2msftngp13.phx.gbl...
now on this task that should be so easy, wtf can't I access the asp:label
control from my .cs code??? : : protected Label myLabel;
This is your user control's protected field, myLabel, of type Label.
void Page_Load(object sender, System.EventArgs e)
{
Label myLabel = new Label( );
This is a local variable in the Page_Load method, named myLabel, that is
covering up the myLabel private field.
myLabel.Text = "and I have success";


This line takes effect, but then this local variable leaves scope at the end
of the Page_Load method and in all this time, nothing has happened to
this.myLabel.Text.

Instead of declaring locally,

Label myLabel = new Label( );

just instantiate the Label you've already got,

myLabel = new Label( );

or, to be more explicit that you want the myLabel field on this user control,

this.myLabel = new Label( );
Derek Harmon
Nov 18 '05 #2

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

Similar topics

1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
1
by: bill yeager | last post by:
I did some more debugging and found the following: 1) I placed the following code in the button event just to see if I could cycle thru the datagrid control collection: <code> Dim strhello As...
3
by: Hutty | last post by:
I'm trying create a calendar control that updates an access database with events. I have some code I managed to piece together. First error I'm running into is the Mycommand.ExecuteNonQuery(). I...
2
by: fxs | last post by:
Hello, I have the following controls on an aspx page: 2 html radio button controls, 1 asp:label control and 1 asp:button control.... <INPUT id="rdo1" type="radio" name="grp1"...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
2
by: Craig | last post by:
This has got to be easy, but I can't figure it out. I have a login control with a login button to process the username,password, etc. I have the login control within a login page, and this page...
1
by: Nathan Sokalski | last post by:
I have a problem that is driving me crazy. I have a User Control composed of three DropDownLists that will be used to select a date. I have everything working except for one thing. When I select a...
3
by: shapper | last post by:
Hello, In have a class inside a compiled DLL where I have the following code: ' Create site map XML document Dim siteMap As XmlDocument = New XmlDocument ' Load site map XML document from...
1
by: cpajoe2001 | last post by:
I am having an issue and after searching around online for a day and half now and finding others with the same problem but yet no solution to my issue I am looking for help. What i have is ServerA...
6
by: =?Utf-8?B?UGFycm90?= | last post by:
I cannot access my SQL database in a browser control created in my C# Windows application program I can, however, access the database from an IE browser. I get the ubiquitous "Login failed for NT...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.