473,832 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="User Controls" TagName="Initia lizer"
Src="initialize r.ascx" %>
<UserControls:I nitializer runat="server" />

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

*** initializer.cs ***
using System.Web.UI.W ebControls;
public class Initializer
{
protected Label myLabel;
void Page_Load(objec t sender, System.EventArg s e)
{
Label myLabel = new Label();
myLabel.Text = "and I have success";
}
}
Nov 18 '05 #1
1 1227
"Davíð Þórisson" <db**@hi.is> wrote in message news:eK******** *****@tk2msftng p13.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(objec t sender, System.EventArg s 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.Te xt.

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
10935
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 my datalist has an id of "Datagrid3". dgChild comes back with "Nothing" while debugging. Here is my code in the itemdatabound event for the datalist: <code>
1
1758
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 String Dim myDataListItem As DataListItem Dim myDatagridItem As DataGridItem Dim myCheckBox As CheckBox
3
2770
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 get an error on this line as it looks for the query. Here's the first piece of the code where I'm able to get display calendar and the input boxes. Just trying to write back to database. Thanks in advance. Public Sub Page_Load(ByVal Sender...
2
11414
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" onClick="clientsidecode();"> <INPUT id="rdo2" type="radio" name="grp1" checked onclick="clientsidecode();"> <asp:Label id="Label1" runat="server">Label</asp:Label> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
7
3023
by: Shimon Sim | last post by:
I have a custom composite control I have following property
2
1417
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 has the form tags in it....... //this doesn't work for the onsubmit <form id="Form1" method="post" runat="server" onsubmit="Button1_Click"> <uc1:Top id="Top1" runat="server"></uc1:Top> <uc1:SideNav id="SideNav1" runat="server"></uc1:SideNav>
1
1666
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 new value from one of the DropDownLists, the code still returns the old value. You will notice that I try to access the SelectedIndex property in DateChanged, which is the eventhandler for all three SelectedIndexChanged events, although I could put...
3
2246
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 ASP.NET web site map siteMap.Load(HttpContext.Current.Server.MapPath(Me.SiteMapUrl)) Me.SiteMapUrl is a property.
1
8995
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 which is a webserver running Win2k3 with IIS6, my domain account is a local administrator on this machine. The web app I am running is trying to write a file to ServerB which is also a Win2k3 machine. On the folder of the machine I am writing to...
6
1720
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 AUTHORITY\NETWORK SERVICE" error message. I researched all the advice on the internet and tried to add an NT AUTHORITY\NETWORK SERVICE login to my database under the Security/Users tab using SQL Server Mangement. However, there is no NT...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10780
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10498
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10540
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9319
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5623
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.