Showing posts with label ASP.NET User controls. Show all posts
Showing posts with label ASP.NET User controls. Show all posts

Tuesday, December 22, 2009

Acccessing User control in Class Library Project in ASP.NET

Hi All,

In one of scnerio. i have to access user control of web application in my Class Library project.I do check what are the possibilities and alternatively found the solution.

Solution:

Implement interface to user control and get access of properties and methods in class library.

   23 public partial class multiupload : Imultiupload


{
...
}

here is my Interface

    9 public interface Imultiupload


{
...
}

in my Class Library project class where i want to access i have just initialize the control like this,

   41 Imultiupload fileupload = null;



and then i have access it by LoadControl method.

  314 fileupload = (Imultiupload)Page.LoadControl("~/inigo/admin/controls/multiupload.ascx");

  315                             fileupload.ControlID = Lib.ToUnderscore(p.Name);

  316                             fileupload.AllowMultipleFileUploads = true;

  317                             fileupload.ButtonText = "Upload Files";



Using Interface to access the user control in class library project is good practice.

Happy Coding :-)