Use several Web Part deployment methods of ASP. NET

Source: Internet
Author: User

Use several Web Part deployment methods of ASP. NET:

1. Use the Web Part deployment method of ASP. NET 2.0 to declare SafeContorl and upload it to the Webpart gallery of Sharepoint. The Walkthrough on MSDN: Creating a Basic Web Part is described in detail.

2. after using the SharePoint Webpart to install VS Extensions for SharePoint, a project type is called webpart, write a webpart, and then F5, The webpart will be deployed to your SharePoint site. A Feature is actually deployed. its principles are also introduced on MSDN: Walkthrough: Creating a Basic SharePoint Web Part

3. In his blog, kaneboy mentioned the use of Feature deployment of DelegateContorl to deploy an ascx file to the site set Feature.

The above three methods have their own advantages and disadvantages. The first two methods use pure Webpart form, which is very troublesome for development, especially for some rich user interfaces. The third method solves the shortcomings of the first two methods, but there is no Code-behind. It is not suitable for enterprise-level development to write code in the ascx file, it is not convenient to use Feature for management after deployment. So today I am going to Demo a way to use the Code-behind user control as a WebPart, And the deployed UserContorl is easy to manage.

Here we use a tool named SmartPart, which is available in the WSS 2.0 era and is now available for versions with WSS 3.0. I downloaded an msi installation package. I don't know why I didn't install the package successfully on both vpcs. After extracting the package to the temporary directory, it didn't reflect it. No way, some have to do it yourself. There is a Cab file in the temporary directory. After Opening this file, I will study it and understand the installation steps.

Step (1): deploy SmartPart. dll to GAC.

Step (2): create a Web Project and develop your user control. The user control of the Demo is called UCPart. ascx.
Front-end code:

 
 
  1. <%@ Control Language="C#" CodeFile="UCPart.ascx.cs" Inherits=
    "DemoWebPart.UCPart" CompilationMode="Always" %> 
  2. <asp:TextBox ID="txbDate" runat="server"> 
  3. </asp:TextBox> 


Background code:

 
 
  1. using System;  
  2. using System.Data;  
  3. using System.Configuration;  
  4. using System.Collections;  
  5. using System.Web;  
  6. using System.Web.Security;  
  7. using System.Web.UI;  
  8. using System.Web.UI.WebControls;  
  9. using System.Web.UI.WebControls.WebParts;  
  10. using System.Web.UI.HtmlControls;  
  11. namespace DemoWebPart  
  12. {  
  13. public partial class UCPart : System.Web.UI.UserControl  
  14. {  
  15. protected void Page_Load(object sender, EventArgs e)  
  16. {  
  17. this.txbDate.Text = DateTime.Now.ToShortDateString();  
  18. }  
  19. }  

The function is simple, that is, assigning a value to a textbox in the background code. After compilation, copy the user control along with the background code file to <% IIS Root Dir %> \ wss \ VirtualDirectories \ xxxx \ UserContorls.

<% IIS Root Dir %> is the Root directory of IIS, and xxxx is the port number of the current Web Application. If you do this for the first time, you need to create a UserContorls folder manually.

 
 
  1. <SafeControl Assembly="SmartPart, Version=1.1.0.0, Culture=neutral, 
    PublicKeyToken=dd064a5b12b5277a" Namespace="SmartPart" TypeName="*" /> 

At the same time, modify <% IIS Root Dir %> \ wss \ VirtualDirectories \ xxxx \ Web. Config. Declare SaftContorl. The preceding section describes how to deploy ASP. NET Webpart.

  1. ASP. NET calls the WCF Service
  2. Analysis of ASP. NET verification controls
  3. Compatibility between the WCF Service and ASMX service in ASP. NET
  4. ASP. NET Applications
  5. ASP. NET HttpModule

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.