-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: sbhavin77
Message 5 in Discussion

  
Hi, 
Go through the attached article. (see the red text) Couple of things to note: 
1. Use @Contorl with className attribute while using user-control programmatically. 
2. User @Reference directive while using user-control programmatically and use 
@Register directive while using user-control declaratively. 
3. NEVER put FORM in .ascx file. 
 - Bhavin 
======================================= 
Just as you can programmatically create an instance of any ASP.NET server control on a 
Web Forms page, you can do the same with user controls by using the containing page's 
LoadControl method. First, however, you must associate a strong type with the user 
control by using the className attribute on the @ Control directive. This is necessary 
because the LoadControl method returns a type of the Control class, and you need to 
cast the user control to the appropriate strong type to be able to set individual 
properties on the control. 
The following example uses the className attribute to strongly type a user control 
saved in the file MyUserControl.ascx.<%@ Control className="MyUserControl" %> 
To create an instance of a user control programmatically        Register the user 
control at the top of the containing Web Forms page with the @ Reference directive. 
When creating the user control programmatically, the strong type for your user control 
is only available to the Web Forms page once you have created a reference to it. For 
example, the following code creates a reference to a user control created in the 
MyUserControl.ascx file. <%@ Reference Control="MyUserControl.ascx" %> Note   When 
creating instances of a user control declaratively in a Web Forms page, use the @ 
Register directive.     Create an instance of the user control, either in the 
code-behind class file or the code declaration block for the containing .aspx file. 
Assign property values as necessary, and add the control to the containing page's 
ControlCollection object using the Add method. This is made available to the page's 
inherited Control.Controls property. In the following example, an instance of 
MyUserControl.ascx is created with its BackColor property set to beige.  
[C#]
Control c1 = LoadControl("MyUserControl.ascx");
((MyUserControl)c1).BackColor = "beige";
Page.Controls.Add(c1);

[Visual Basic]
Dim c1 As UserControl = LoadControl("MyUserControl.ascx")
CType(c1, MyUserControl).BackColor = "beige"
Page.Controls.Add(c1)

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to