Add a WebPart to an Application page - asp.net

I have a "Data view web part" created from SharePoint Designer. I added the web part to my visual studio project as a "Web Part" . I want to know how to add the web part to an application page.

Hi i know its kind of late but, today i had to do the same thing, so i followed a great answer on sharepoint.stackexchange.com. But basically is like adding any other asp.net control on an APS.NET page.
First you need to define the prefix for that assembly
<%# Register tagprefix="prefix" namespace="NameSpaceOfTheWebPart" assembly="FullAssemblyName" %>
ex:
<%# Register tagprefix="csm" namespace="MySolution.VisualWebPart" assembly="MySolution Version=1.0.0.0, Culture=neutral, PublicKeyToken=335eef5f6f60e56b" %>
and then add the web part to the page (on the main place holder) using the required attributes by asp.net (ID and runat).
<prefix:WebPartClassName ID="ID" runat="server" />
The only thing is that you won't be able to edit the page and modify the Web Part through the browser, if you need to modify any other property of the Web Part you will have to do it from the html or code behind.
here is the url of the link i followed:
https://sharepoint.stackexchange.com/questions/26508/is-it-possible-to-add-web-parts-to-an-application-page
i hope it helps.

Related

Unknown server tag 'asp:UpdatePanel' only when doing Build or Publish

This ASP.NET web application was developed in VS2010 and I was asked among other things to upgrade the solution to 2012. When I did, I could no longer publish the project because of the error in subject plus the same error about asp:UpdateProgress. But the application runs fine when I start it from VS2012, including the page that uses those two controls!
A bit of history: initially the page was using MS AJAX controls, but at some point (Feb 2009) it was changed to use AjaxControlToolkit 3.5.60501 and the following line was added at the top of the ASCX file and the master page file:
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AJAX" %>
At the same time asp:ScriptManager control in the master page was replaced with
<AJAX:ToolkitScriptManager ID="ScriptManager1" AsyncPostBackTimeout="180" runat="server"
EnableScriptGlobalization="true" EnableScriptLocalization="true">
<Services>
<asp:ServiceReference Path="AutoComplete.asmx" InlineScript="true" />
</Services>
</AJAX:ToolkitScriptManager>
Apparently AJAX tag prefix here replaced the asp tag prefix. But that does not seem to break functioning of the UpdatePanel and UpdateProgress. The project still publishes fine from VS2010. Publishing/building in VS2012 is the only thing which is broken now.
Do I need an updated version of AjaxControlToolkit or is the problem elsewhere?

Why "CodeBehind" on Web App or WCF App?

I'd like clarification of what seems to be a contradiction in MSDN documentation.
MSDN makes very clear the distinction between a "web site" and a "web application." For example, it says you should use an "application" instead of a "site" if...
You want to avoid putting source code on a production server.
Ok, sounds good, but when you create an ASP.NET MVC "app" or a WCF service "app", the first thing you get is a description file with a CodeBehind that specifies what source code to reference. Examples:
For ASP.NET MVC
<%# Application Codebehind="Global.asax.cs" Language="C#" Inherits="Sample.MvcApplication" %>
For a WCF service app
<%# ServiceHost CodeBehind="MyService.svc.cs" Language="C#" Service="Sample.MyService" %>
In both these "app" examples, the "CodeBehind" assumes you have placed source code on your production server. In short, what you receive from a Visual Studio "App" or "project" template basically contradicts the claim made by MSDN documentation.
What makes this more strange is that, at least in some caes, this doesn't need to be this way. For example, another valid way for the WCF service description file to be generated is like this:
<%# ServiceHost Language="C#" Debug="true" Service="Sample.AccountService" %>
<%# Assembly Name="Sample.AccountService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" %>
With the "Assembly" directive, it is not necessary to specify a CodeBehind target. If a purpose of a WCF app (in contrast with a WCF site, which is also a Visual Studio option) is to have no source code on a production server, why then is the service definition file not generated as shown in the last sample above?
What is the rationale that allows this apparent contradiction?
You want to avoid putting source code on a production server.
This is referring to the ability use non-compiled code. With a website, you have the ability to copy your aspx.cs or aspx.vb files (in clear text) along the aspx files and have them run. You can also modify them in clear text because they are not compiled.
A web application differs because must be compiled, the source code exists in DLLs.

How to load webusercontrol from classlibrary

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.

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