programmatic usercontrol woes

M

matt.delvecchio

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
 
M

matt.delvecchio

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
 
M

matt.delvecchio

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top