UserControl question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Will

    #1

    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.NullRefe renceException: Object reference not set to
    an instance of an object.

    here's a snippet:

    public TextBox TBName;

    Page s = ((Page)HttpCont ext.Current.Han dler);
    UserControl u = ((UserControl)s .FindControl("U CName"));
    TBName = ((TextBox)ddd.F indControl("TBN ame"));
    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.
  • MS News \(MS ILM\)

    #2
    Re: UserControl question

    ddd ? where is it defined?
    u.FindControl(" TBName")

    "Will" <wswelch@comcas t.net> wrote in message
    news:0bda01c368 27$4c348730$a00 1280a@phx.gbl.. .[color=blue]
    > 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.NullRefe renceException: Object reference not set to
    > an instance of an object.
    >
    > here's a snippet:
    >
    > public TextBox TBName;
    >
    > Page s = ((Page)HttpCont ext.Current.Han dler);
    > UserControl u = ((UserControl)s .FindControl("U CName"));
    > TBName = ((TextBox)ddd.F indControl("TBN ame"));
    > 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.[/color]


    Comment

    Working...