How to load webusercontrol from classlibrary - asp.net

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

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

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" />

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.

Related

In ASP.NET where and all we can refer the assembly reference?

In ASP.NET where and all we can refer the assembly reference in Project? for ex: generally we can refer the file in web.config file as like below
<%# Register assembly="System.Web" namespace="System.JavaScript.Web" tagprefix="ex" %>
Except this what are the other pages in which we can refer assembly as like above.
secondly you can refer the assembly in project. Right click on references and select the required assembly, and click add. This will add assembly reference to your project.
Some assemblies like ajaxtoolkit.dll or if you are using some partial views (ascx) pages, then you can use the reference which you have mentioned.

Can I use Asp.net control in a SharePoint2010 webpart

I am new to SharePoint development, I am using VS2010 and SharePoint2010.
I am wondering whether there is a restriction using a asp.net ListView in a SharePoint web part control. Because for some reason the intelliSense does not provide me ListView, just a GridView
Thanks
Web Parts in SharePoint are ASP.NET Web Parts. So you can freely use without any restrictions the ASP.NET Controls.
The Code Behind might use the SharePoint API but everything you can do is provided by ASP.NET.
Edit:
Are you missing an Reference for the ListView ? You need to add a reference to System.Web.Extensions in order to use the ListView
There is not such kind of restriction in SharePoint. You can use any kind of asp.net control in SharePoint.
For ListView intelliSense, you need to register system.web.extensions in your control or webpart before using ListView.
Please copy below code for register Library:
<%# Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.WebControls" TagPrefix="asp" %>

Register custom class in assembly with web project

I'm using web project and web forms.
I create Custom Class
Namespace CustomWebControls
Public Class NoValidationDDL
Inherits DropDownList
End Class
End Namespace
and i try to register this class in assembly web.config page section
<controls>
<add tagPrefix="customDDL" namespace="CustomWebControls" assembly="ae" />
</controls>
and try to use in ascx
<customDDL:NoValidationDDL ID ="id" runat="server"></customDDL:NoValidationDDL>
How can i do this in web project?
This should work (assuming the assembly name for your project is ae) - make sure that you build the project after creating/modifying your custom control. Unless updated 'ae.dll' is present in your bin directory, intellisense etc will not work.
Instead of modify web.config, you may also try register control at page(aspx) or control(ascx) level by adding register directive after page directive:
<%# Register Assembly="ae" Namespace="CustomWebControls" TagPrefix="customDDL" %>

VB webform in IronPython asp.net website

I tried to bring a previously done webform made in vb.net to an IronPython asp.net website with no luck. After seeing it didnt work, I tried to write the simplest codebehind vb.net webform to see if there was a problem with vb.net in an IronPython website and I got the following usual error
"be sure that the defined class in this file matchs with the one in the attribute inherits and that it extends the right base page (page or control)" (sorry if the translation isnt the most accurate I get that message in spanish)
but if I create a vb.net webform in the same website, with the sourcecode in the same file (with the vb.net code between script runat="server" tags in the same page) I get no problem.
Do I have to configure something for both kind of sourcecode languages to run in such way in the same IronPython website, like configuring something in the webconfig file or is there some compatibility issue for doing that which can't be resolved?
The code between <script /> tags is compiled dynamically when the page is first run. This enables you to mix languages. However, the classes in your code-behind files are statically compiled into an assembly by VS.NET ... and a VS.NET project can only support one language at a time.
One solution is to put your VB.NET code-behinds in a separate assembly. For example:
Add a new VB Class Library project to your existing solution
Add a reference to System.Web
Create your VB.NET code-behinds. They should be normal classes inheriting from System.Web.UI.Page.
In your ASP.NET website project, add a reference to the new project
Edit the # Page directives in your *.aspx files to inherit the classes in the new project
e.g. <%# Page Inherits="YourNewVBClassLibraryProject.MyVBCodeBehinds" ... /> where the Inherits attribute contains the relevant namespace-qualified class name
Thanks for the reply Serilla. Your information was interesting but I simply solved it by creating the app_folder and adding the vb files there. Do you think I could have some future problem for doing so?
The problem with the vb files was when these lines in the web.config were enabled for Ironpython to work
<pages compilationMode="Auto" pageParserFilterType="Microsoft.Web.Scripting.UI.NoCompileCodePageParserFilter" pageBaseType="Microsoft.Web.Scripting.UI.ScriptPage" userControlBaseType="Microsoft.Web.Scripting.UI.ScriptUserControl">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
when I removed them, vb code behind files worked but ironpython didnt. When the lines were there, Ironpython code behind files worked but vb ones didnt

How do I install and use the ASP.NET AJAX Control Toolkit in my .NET 3.5 web applications?

How do I get it to work with my project?
http://ajax.asp.net/
http://www.codeplex.com/AjaxControlToolkit/
Install the ASP.NET AJAX Control Toolkit
Download the ZIP file
AjaxControlToolkit-Framework3.5SP1-DllOnly.zip
from the ASP.NET AJAX Control
Toolkit Releases page of the
CodePlex web site.
Copy the contents of this zip file
directly into the bin directory of
your web site.
Update web.config
Put this in your web.config under the <controls> section:
<?xml version="1.0"?>
<configuration>
...
<system.web>
...
<pages>
...
<controls>
...
<add tagPrefix="ajaxtoolkit"
namespace="AjaxControlToolkit"
assembly="AjaxControlToolKit"/>
</controls>
</pages>
...
</system.web>
...
</configuration>
Setup Visual Studio
Right-click on the Toolbox and select "Add Tab", and add a tab called "AJAX Control Toolkit"
Inside that tab, right-click on the Toolbox and select "Choose Items..."
When the "Choose Toolbox Items" dialog appears, click the "Browse..." button. Navigate to your project's "bin" folder. Inside that folder, select "AjaxControlToolkit.dll" and click OK. Click OK again to close the Choose Items Dialog.
You can now use the controls in your web sites!
You can easily install it by writing
Install-Package AjaxControlToolkit in package manager console.
for more information you can check this link
If you are using MasterPages and Content pages in your app - you also have the option of putting the ScriptManager on the Masterpage and then every ContentPage that uses that MasterPage will NOT need a script manager added. If you need some of the special configurations of the ScriptManager - like javascript file references - you can use a ScriptManagerProxy control on the content page that needs it.
you will also need to have a asp:ScriptManager control on every page that you want to use ajax controls on. you should be able to just drag the scriptmanager over from your toolbox one the toolkit is installed following Zack's instructions.
It's really simple, just download the latest toolkit from Codeplex and add the extracted AjaxControlToolkit.dll to your toolbox in Visual Studio by right clicking the toolbox and selecting 'choose items'. You will then have the controls in your Visual STudio toolbox and using them is just a matter of dragging and dropping them onto your form, of course don't forget to add a asp:ScriptManager to every page that uses controls from the toolkit, or optionally include it in your master page only and your content pages will inherit the script manager.

Resources