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

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: sbhavin77
Message 4 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 
<MSHelp:link tabIndex=0 
keywords="frlrfSystemWebUITemplateControlClassLoadControlTopic">LoadControl</MSHelp:link>
 method. First, however, you must associate a strong type with the user control by 
using the className attribute on the <MSHelp:link tabIndex=0 
keywords="cpconControlDirective">@ Control</MSHelp:link> directive. This is necessary 
because the LoadControl method returns a type of the <MSHelp:link tabIndex=0 
keywords="frlrfSystemWebUIControlClassTopic">Control</MSHelp:link> 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 <MSHelp:link tabIndex=0 
keywords="gngrfReference">@ Reference</MSHelp:link> 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 <MSHelp:link tabIndex=0 
keywords="cpconRegister">@ Register</MSHelp:link> 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 <MSHelp:link tabIndex=0 
keywords="frlrfSystemWebUIControlCollectionClassTopic">ControlCollection</MSHelp:link> 
object using the <MSHelp:link tabIndex=0 
keywords="frlrfSystemWebUIControlCollectionClassAddTopic">Add</MSHelp:link> method. 
This is made available to the page's inherited <MSHelp:link tabIndex=0 
keywords="frlrfSystemWebUIControlClassControlsTopic">Control.Controls</MSHelp:link> 
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) Note   When you add controls to the ControlCollection object by 
using the Add method, they are placed in the collection in the order they are 
processed. If you want to add a control to a specific position in the collection, use 
the <MSHelp:link tabIndex=0 
keywords="frlrfSystemWebUIControlCollectionClassAddAtTopic">AddAt</MSHelp:link> method 
and specify the index location where you want to store the control.

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

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