473,480 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

UserControl question

I have an aspx page, with an ascx user control on it and
that ascx file has a code-behind page.

I have an event handler for a submit button in the code
behind and I want to check the text field of a textbox
which is in the ascx user control.

for some reason I keep getting the error:
System.NullReferenceException: Object reference not set to
an instance of an object.

here's a snippet:

public TextBox TBName;

Page s = ((Page)HttpContext.Current.Handler);
UserControl u = ((UserControl)s.FindControl("UCName"));
TBName = ((TextBox)ddd.FindControl("TBName"));
TBName.Text = "hello";

I get the error on that last line.. I don't understand
why it says the reference is not set to an instance.. the
TextBox object TBName exists in my ascx file, I declare it
in my code behind as well.
Nov 17 '05 #1
1 1151
ddd ? where is it defined?
u.FindControl("TBName")

"Will" <ws*****@comcast.net> wrote in message
news:0b****************************@phx.gbl...
I have an aspx page, with an ascx user control on it and
that ascx file has a code-behind page.

I have an event handler for a submit button in the code
behind and I want to check the text field of a textbox
which is in the ascx user control.

for some reason I keep getting the error:
System.NullReferenceException: Object reference not set to
an instance of an object.

here's a snippet:

public TextBox TBName;

Page s = ((Page)HttpContext.Current.Handler);
UserControl u = ((UserControl)s.FindControl("UCName"));
TBName = ((TextBox)ddd.FindControl("TBName"));
TBName.Text = "hello";

I get the error on that last line.. I don't understand
why it says the reference is not set to an instance.. the
TextBox object TBName exists in my ascx file, I declare it
in my code behind as well.

Nov 17 '05 #2

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

Similar topics

8
3159
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
4
7950
by: Mark Friedman | last post by:
I can't seem to figure out how to get a reference to a UserControl in the code-behind for the page that contains the control. All the examples I've seen show how to pass property values from the...
0
1415
by: Sebastian Hiller | last post by:
Hello, i'm new to .Net (i'm using VB as language and i'm working in the code-behind mode) and i can't solve the following problem: I have a WebForm and want to Add a UserControl...
1
6805
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
41
4236
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
12
2177
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
0
2076
by: oliver | last post by:
QUESTION: How to access an object embedded in a UserControl through Javascript file? Another way to ask this question: How to execute script from a UserControl, accessing other objects in that...
1
3220
by: Giovanni | last post by:
Dear Friends/Gurus, I have exhausted myself and have yet no solution to the following: I have an ASP.NET 2.0 Survey type application. On a page, I have placed a GridView which is bound to an...
10
2391
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
1
1768
by: RvGrah | last post by:
I have a usercontrol written in C# that exposes a public property of type double. This control is used in a program written in VB.net. If I set the value to 66.6667, it stays fine, I can break...
0
7051
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
6915
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...
0
7054
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,...
1
6750
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...
0
6993
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...
0
5353
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,...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.