Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP.NET (Non-Forum Related)
 Dynamically Loading User Controls in ASP.NET
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

blackinwhite
Average Member

Turkey
657 Posts

Posted - 18 December 2006 :  14:52:15  Show Profile
Dynamically loading user control is ok, it works great, but I can't pass a parameter to user control, it gives me

CS0117: 'System.Web.UI.Control' does not contain a definition for 'nameFile'

error

here is the code;


		//STage'i oluŝtur
		Control TemplateStage = LoadControl("../ucx/Template.Stage.SWFObject.ascx");
		Controls.Add(TemplateStage);
		TemplateStage.nameFile = itemString;
		stageContent.Controls.Add(TemplateStage);
		stageContent.Visible=true;

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 18 December 2006 :  17:59:17  Show Profile  Visit HuwR's Homepage
have you declared nameFile as a public property in your usercontrol as below ?

private string _nameFile;

public string nameFile //property
{
set { _nameFile = value; } //write into property
}

also, you will run into problems adding the same usercontrol to two different control sets, you should instantiate a second copy to add it to the second control, and you should also load it using the tagname that is set in your tag declaration not using the generic Control type, which is possibly the source of your problem. see example below.

PostingOptions POt = (PostingOptions)Page.LoadControl("~/User_Controls/PostingOptions.ascx");
POt.TopicId = TopicId;
POTop.Controls.Add(POt);

PostingOptions POb = (PostingOptions)Page.LoadControl("~/User_Controls/PostingOptions.ascx");
POb.TopicId = TopicId;
POBottom.Controls.Add(POb);
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.1 seconds. Powered By: Snitz Forums 2000 Version 3.4.07