469,644 Members | 1,980 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,644 developers. It's quick & easy.

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 1080
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Mark Friedman | last post: by
reply views Thread by Sebastian Hiller | last post: by
12 posts views Thread by Joe | last post: by
reply views Thread by oliver | last post: by
1 post views Thread by Giovanni | last post: by
1 post views Thread by RvGrah | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.