views:

247

answers:

3

I have a classlibrary. This library contains widget.ascx control. How to load this webusercontrol from web. I know "LoadControl". But this not applicable.

How can i load web usercontrol from library?

2009.09.24

My main goal is i'm creating addon based web application. Every addon will be widget of web application.

I need dynamically load web usercontrol from library

A: 

You need to add a reference of the library to your web project.

Then instantiate it as you would with any other control, either programatically or in an @Register directive.

Kindness,

Dan

Daniel Elliott
I need load dynamically
ebattulga
Like he said, add a reference to the class library assembly, and in your code add a Using/Include statement at the top for the namespace and then use it like anything else. When done initializing the object, you can add it to the page with the Controls.Add method.
Yadyn
A: 

In addition to obviously adding the DLL to your project references, you also need to register the control. You can do this on each page that will use the control, but I usually prefer to do it in web.config. As a quick example, here's the line I used to register the Infragistics UltraWebGrid control in my app.

<pages>
   <controls>
      <add tagPrefix="ig" namespace="Infragistics.WebUI.UltraWebGrid" assembly="Infragistics35.WebUI.UltraWebGrid.v8.2, Version=8.2.20082.1000, Culture=neutral, PublicKeyToken=7DD5C3163F2CD0CB"/>
   </controls>
</pages>

TagPrefix works kind of like an in-page namespace, so if I had a bunch of controls I was importing from one DLL, they'd probably all have the same TagPrefix. In the page, I'd simply reference my control as follows:

<ig:UltraWebGrid runat="server" SetSomeOtherPropertiesToo="blah" />
Sterno
A: 

I am not sure how the .ascx file is added to your class library. Normally user controls are loaded using LoadControl which requires an existing file. In case the user control is compiled as embedded resource in your class library you could use GetManifestResourceStream() to read the user controls' contents and then ParseControl to create a control from the string read using GetManifestResourceStream.

korchev
i'm copied widget.ascx from web application to class library.
ebattulga