Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Accessing Control from Class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TisMe - 08 Dec 2007 22:32 GMT
Hi All,

I have a problem that I am struck on, can you help?

1) I drag labelX onto the page
2) Create a new class 'myClass' which inherits system.web.ui.page
(Outside of the _default class for the page)
3) I now want to change a property of labelX, from a method within
myClass - How can I do this?

I have tried this (Within 'myClass')...

Label lblMess = new Label();
lblMess = (Label)FindControl("lblMessage");
lblMess.Text = "Hello Again World";

...which results in this error:
"Object reference not set to an instance of an object"

I know this means I am trying to access a null object, but really not
sure what to do to fix this?

I did think perhaps my method in 'myClass' needs to accept a byref
parameter type matching the control, is there another way? I'm sure I
am missing something simple here!

Thanks!!
Simon.
SMiGL - 10 Dec 2007 07:57 GMT
> I have a problem that I am struck on, can you help?
>
[quoted text clipped - 12 lines]
> ...which results in this error:
> "Object reference not set to an instance of an object"

Perhaps 'myClass'  not tie with you aspx page and so you can`t find
label.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="'<Name you
file>.aspx.cs"
   Inherits="<Class name>" Title="Untitled Page" %>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.