C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Passing Value To a User Control From a Web Page


Posted Date: 31 Jan 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms

Posted By: VasanthRaj       Member Level: Gold
Rating:     Points: 10




This article will give you a brief idea how to load a user control dynamically and pass values to it. This can be also taken as a best example for the use of properties.



Step1: Create a web page- default.aspx and place a place holder in it.

Step2: Create a user control- my.ascx and place a label in it.



Step3:In my.ascx.cs write the following code



public string prop //property

{

set { Label1.Text = value; } //write into property

}



Step4: Pace the following tag in default.aspx


<%@ Register Src="my.ascx" TagName="my" TagPrefix="uc1" %>



Step5: Place this code in default.aspx.cs



Protected void Page_Load(object sender, EventArgs e)

{

if (!Page.IsPostBack)

{

my uc = (my)Page.LoadControl("my.ascx" ); //loading the user control dynamically

uc.prop = "anoop"; //assign the label text a value

PlaceHolder1.Controls.Add(uc);

}





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
User control  .  Aspx  .  Asp.net  .  Accessing control  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Get current page name
Previous Resource: RegisterStartupScript while using AJAX Update Panel
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

efax

Contact Us    Privacy Policy    Terms Of Use