Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 14th, 2009, 01:34 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default instance a user control with Code Behind.

heyheyhey its your favorite noob ever...

ok so i need to instance my user control using code behind... been at this for a couple hours almost ( i exceeded my rate of two lines of code per day )

here is what i got:

User Control Class:
(it spawns a messageSending type of application, just a txtbox, send button, and a list of friends...) here i am trying to create the control after the user clicks the "Compose" link

Code:
 
UserControls_SendToContactsPanel objPanel = new UserControls_SendToContactsPanel();
objPanel.Initialize();
in the Initialize() method is the following:

Code:
 
publicvoid Initialize()
{
string user = HttpContext.Current.User.Identity.Name.ToString();
string conString = WebConfigurationManager.ConnectionStrings["myHomeConnection"].ConnectionString;
DataContext db = newDataContext(conString);
MembershipUser myObject = Membership.GetUser();
string UserID = myObject.ProviderUserKey.ToString();
var friends = (from m in db.GetTable<FriendList>() where m.UserID == UserID select m.FriendID);

if (friends != null)
{
ListView1.DataSource = friends;
ListView1.DataBind();
}

}
it appears that ListView1 doesnt exist... so should i have called Init on the Page_Loaded event? im going to try that... if it doesnt work.. im out of ideas.
 
Old March 14th, 2009, 01:42 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

YESYESYES it worked!!!!
however...

where is it? it doesnt show up... the page reloads... but no messageSendingBox type thing... shows up?

TO THE GOOGLE MACHINE!!!
 
Old March 14th, 2009, 02:33 AM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

ok... no. i lied... im back to this:

Code:
 
UserControls_SendToContactsPanel objPanel = newUserControls_SendToContactsPanel();
objPanel.Initialize();
so ... yea. i really dont know whats going on there...

aparently Initialize() gets called before objectPanel's Listbox control is created.
 
Old March 14th, 2009, 05:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Rather than instantiating the controls yourself, look into LoadControl:
http://msdn.microsoft.com/en-us/libr...adcontrol.aspx

When you load controls using LoadControl they'll "catch up"' to get aligned with the page's life cycle.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
iceman90289 (March 14th, 2009)
 
Old March 14th, 2009, 01:38 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

thanks imar





Similar Threads
Thread Thread Starter Forum Replies Last Post
user control code chroniclemaster1 ASP.NET 2.0 Professional 11 September 25th, 2008 03:53 PM
user control / code behind question whyulil General .NET 3 January 11th, 2005 11:17 AM
Loading user control dynamically from code-behind jacob ASP.NET 1.0 and 1.1 Basics 2 April 12th, 2004 06:06 PM
User Control / Code-behind ViagraFalls ASP.NET 1.0 and 1.1 Basics 3 November 1st, 2003 09:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.