User Controls are classes which inherit from System.Web.UI.UserControl. To add a custom code or controls to pages in a Sitefinity site, developers could
create and upload ASP.NET User Controls (.ascx files). Below are instructions on how to create a simple User Control that wraps a RadUpload control for file
uploading.
Creating a User Control in Visual Studio
In order to create a user control, the respective file should be created in and/or added to the Sitefinity project in Visual Studio:
- Launch Microsoft Visual Studio.
- Select File, then New, and then Web Site.
- In the New Web Site dialog box, select a location in the file system. Select the C# language.
- Click OK.
- Select the Web User Control template.
- Click Open.
- Right-click the Web site in Solution Explorer and select Add New Item.
- In the Add New Item dialog box, select the Web User Control template.
- Check the Place Code in Separate File check box.
- Select the C# language.
- Name the new item UploadControl.ascx.
- Click Add.
Adding Controls and Code to the User Control
The following code should be put into the user control so that to add the RadUpload control which is a ready-to-use control that uploads files:
- Select the Design tab of UploadControl.ascx.
- Drag a RadUpload control from the Toolbox to the UploadControl.ascx design surface.
- Select the Source tab of UploadControl.ascx.
- Modify the source to add a submit button after the RadUpload control, as follows:
|
RadUpload
|
Copy Code |
|
<radU:RadUpload ID="RadUpload1" runat="server"/><br/>
<br/>
<asp:Button ID="btnSubmit"
runat="server" Text="Submit" OnClick="btnSubmit_Click"/>
|
- Right-click the design surface and select View Code.
- Add the following code to the UserControl, just above the existing Page_Load method:
| C# |
Copy Code |
|
public string TargetFolder{ get {
return RadUpload1.TargetFolder; }
set { RadUpload1.TargetFolder = value; }}
protected void btnSubmit_Click(object sender, EventArgs e){ bool resultsExist = RadUpload1.UploadedFiles.Count > 0;}
|
- Select Build Solution from the Build menu.
For instructions on how to upload and use this user control, see Uploading User Control to
Toolbox
See Also