programmatic usercontrol woes

Discussion in 'ASP .Net Building Controls' started by matt.delvecchio@shell.com, May 19, 2006.

  1. Guest

    hello,

    i have a user control that works great, when its used as a design-time
    controls. however, when i try to use it as a programmtic control, im
    running into troubles.

    the control is pretty simple: it has a textbox, and a grid. in my
    webform, on button_click i call one of its methods to do stuff (like
    bind data and set a value to the textbox), and it works great.

    but, when i try to do this from a new programmatic instance of the
    control, it breaks anytime i try binding data/text to its child
    controls. ala:


    webform.aspx.cs

    private void btnSubmit_Click(object sender, System.EventArgs e)
    {
    My.Controls.ResultsPane results = new My.Controls.ResultsPane();

    results.SetIt();
    }

    resultsPane.ascx

    <span class="lb01">Title: </span>
    <asp:TextBox ID="tbTitle" Runat="server"/>

    resultsPane.ascx.cs

    protected TextBox tbTitle;

    public void SetIt()
    {
    //breaks -- Object reference not set to an instance of an object.
    tbTitle.Text = "xxx";
    }


    ....any idea whats up?? ive noticed that quickwatching the tbPackage
    yields "<undefined value>", whereas i was expecting properties related
    to the textbox.


    thanks!
    matt
    , May 19, 2006
    #1
    1. Advertising

  2. Guest

    ah, ive been working w/ server controls too long... the syntax for user
    control loading is different:

    My.Controls.ResultsPane results =
    (My.Controls.ResultsPane)LoadControl("~/controls/resultsPane.ascx");

    ....then you can do stuff w/ it, add it to the page, etc.


    matt
    , May 19, 2006
    #2
    1. Advertising

  3. Guest

    ah, ive been working w/ server controls too long... the syntax for user
    control loading is different:

    My.Controls.ResultsPane results =
    (My.Controls.ResultsPane)LoadControl("~/controls/resultsPane.ascx");

    ....then you can do stuff w/ it, add it to the page, etc.


    matt
    , May 19, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. huobazi
    Replies:
    1
    Views:
    683
    David Waz...
    Jul 3, 2003
  2. Rajesh Tiwari

    Can we use a usercontrol inside a usercontrol

    Rajesh Tiwari, Aug 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    410
    Rajesh Tiwari
    Aug 12, 2003
  3. nail
    Replies:
    0
    Views:
    1,539
  4. Replies:
    2
    Views:
    316
  5. programmatic usercontrol woes

    , May 18, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    82
Loading...

Share This Page