0

Hey guys,
I've created a CustomFileUpload class which is inherited from the original FileUpload class, I'm gonna have to say it's not actually a UserControl it's a simple class which can be seen below

using System;
using System.Web;

public class CustomFileUpload : System.Web.UI.WebControls.FileUpload
{
    public string Directory { get; set; }
}

I need to know how I can use the control in my page, maybe something like <@Registe ... when we create a usercontrol.

0

3 Answers 3

2

This is called a custom server control. You can read an indepth walkthrough about them. You will need to have the server control reside in an assembly that is separate from your project and then reference the assembly into your project.

The syntax you want to use to put the control on the page is:

<%@ Register Assembly="YourAssemblyName" TagPrefix="myControl" Namespace="YourNamespaceName"%>

Then you can reference the control:

<myControl:CustomFileUpload .... />

An easy way to do this is to add the control to your toolbox. Then you can drag the control from the toolbox onto any page. The Register will be created automatically. To add the control to the toolbox

  1. Right click on the toolbox tab where the control should reside, select choose items. (You can create a new tab or use an existing one).
  2. Select Browse
  3. Browse to and select your assembly, click Open
  4. Your control should now appear in the toolbox tab.
Sign up to request clarification or add additional context in comments.

Comments

1

You can do:

<%@ Register TagPrefix="my" Namespace="My.Namespace" Assembly="MyAssembly" %>

You can also do this at the config level:

<system.web>
  <pages>
    <controls>
      <add tagPrefix="my" namespace="My.Namespace" assembly="MyAssembly" />
    </controls>
  </pages>
</system.web>

Then use in your page:

<my:CustomFileUpload runat="server" ... />

Comments

1

You need to put your class in a Namespace and register it like this

<%@ Register tagprefix="tagprefix" Namespace="Your Namespace" Assembly="The Assembly" %>

Then you can use the control like this

<tagprefix:CustomFileUpload runat="server" />

http://msdn.microsoft.com/en-us/library/c76dd5k1(v=VS.100).aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.