Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Nevron Chart
Search :       Advanced Search »
Home » ASP.NET & Web Forms » ASP.Net User Control as Web Parts

ASP.Net User Control as Web Parts

In this article I would like to give answers to some of the terms and also given some steps to deploy the web part.

Author Rank :
Page Views : 21808
Downloads : 278
Rating :
 Rate it
Level : Intermediate
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
TestPart.zip
 
 
Nevron Chart
Become a Sponsor
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Q: What is Windows Sharepoint (WSS)?
Ans: Windows sharepoint is new technology, which is available in the form of service on Windows 2003 server. It uses CAML (Collaboration application markup language) Wss is more content management based with document libraries and lists.

Q: What is Share Point Portal?
Ans: Windows share point portal offering features like global navigation and searching.

Q: What is document library?
Ans: A document library is where you upload your documents, they consists of row and columns with links to the documents

Q: What is meeting workspace?
Ans: Documents workspace consists of information surrounding a single or multiple documents.

Q: What is a web part?
Ans: Web parts are nothing but the integrated controls which perform some specific task. In short web part is nothing but xml queries to full sharepoint list or document.

Q: What is web part zone?
Ans: Web part zone consist of zonetemplate, and it is nothing but a container in which we can drag and drop user control.

Q: What is DWP?
Ans: DWP is nothing but name of web part file extension

Q: What are various kinds of roles user can have?
Ans: 1. Reader: Has read only access to the web parts
        2. Contributer: Can add content to existing document libraries and lists.
        3. Web Designer: Can add content to the existing document libraries and lists
        4. Administrator: Has full control of the web site

Q: What are the steps for deploying web part on virtual server gallery?
Ans: These steps are more specific to the windows share point server 2003 & web part developed in ASP.net 2003

  • Open the web part project in visual studio
  • Choose file -> Add Project -> New Project -> Setup and deployment project -> Add -> Project Output
  • Select the setup project in the solution explorer and choose project ->Add - > Project output.
  • Select Primary output and content files from the web part project and choose  OK, visual studio adds those items to the setup project.
  • Choose Build -> Rebuild Solution (By doing this visual studio rebuilds the web part assembly and package the assembly and content files in the CAB file)
  • Copy the resulting CAB file to the webparts folder
  • Run stsadm.exe to install the CAB file on the server for e.g.

You can locate stsadm.exe file at following location:

C:\program files\common files\Microsoft shared\web server extension\60\bin\

You can run following command using command prompt

Stsadm - o addwppack - filename "c:\inetpub\wwwroot\Calendar.CAB" This will install Calendar web part to the "Bin" directory of the virtual server. And this will be available to drag and drop in share point server 2003 under Virtual Gallery section

For removing a web part from the list we have to use following command on the command prompt.

Stsadm-o deletewppack -name "Calendar.CAB"

Q. Explain about share point security?
Ans: When web part is deployed under Bin directory .net uses CAS to check if a peace of code has permission to run on the machine. Normally we will face permission issue which can be handled by different ways:

Changing trust level define by wss under c:\program files\common files\Microsoft shared\web sharepoint\60\config\ in wss_minimumaltrust.config, wss_mediumtrust.config we can set <trustlevel name="wss_medium" >

We can deploy assemblies under GAC

Create custom policy file that will grant full trust to your assemblies

Here is simple web part, which displays all the author lists. For this I am having user control called as Display.ascx which fetch author records from the database "Tbl_Authors" which is as:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Display.ascx.cs" Inherits="Display" %>

<asp:DataGrid ID="dgProducts" runat="server" AutoGenerateColumns=true></asp:DataGrid>

Display.ascx.cs Code behind file is as:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Display : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!(Page.IsPostBack))
        {
            BindData();
        }
    }

    public void BindData()
    {
        SqlConnection sqlCon = new SqlConnection("server=Atlas; UID=sa; Password=; Database=master");
        try
        {
            if (sqlCon.State == ConnectionState.Closed)
            {
                sqlCon.Open();
                SqlCommand sqlComd = new SqlCommand("SELECT * FROM Tbl_Author", sqlCon);
                SqlDataAdapter sqlDa = new SqlDataAdapter(sqlComd);
                DataSet dtSt = new DataSet();
                sqlDa.Fill(dtSt);
                dgProducts.DataSource = dtSt;
                dgProducts.DataBind();
            }
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);
        }
        finally
        {
            sqlCon.Close();
        }
    }
}

I have Default.aspx file as below in which I have registered my user control.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagName="Display" TagPrefix="Author" Src="~/Display.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <
html xmlns="http://www.w3.org/1999/xhtml" >
   <
head runat="server">
     <
title>Untitled Page</title>
   </
head>
   <
body>
       <
form id="form1" runat="server">
          <
asp:WebPartManager ID="dispManage" runat="server" />
          <
asp:WebPartZone ID="dispZone" runat="server">
           <ZoneTemplate>
             <
Author:Display id="wbCntrl" runat="server" />
           </
ZoneTemplate>
       </
asp:WebPartZone>
   </form>
  </
body>
</
html

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Munir Shaikh
Munir is MCP in Microsoft .NET Framework 3.5, Windows Communication Foundation
Appl ication Developmen, software Developer/ project lead with 9 Yrs development experience who works on IT projects mainly for Microsoft and some open source technologies. Most of these projects have been intranet based web applications / sites with SQL/Oracle as back-end. Currently he  is focusing more on Silverlight, WCF & WPF development. He had worked on payment gateway implementation. He is experienced in Insurance, Supply Chain management, Trading, Real-Estate & currently Legacy modernization domain.
Apart from this he has implemented on CMMi L3 for organization and has good understanding of process. He has also involved in consulting activities like Architecture Review, Project Plan, HLD, LLD, Risk Management etc....
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Comments
Dynamically adding hyperlinks to a panel which is added into the webpart by Zainab On January 30, 2009
Hi,

 I am working on an Intranet Portal project, in which I am creating dynamic webparts that fetches data from XML. When I generate the webparts It displays the title of the panel but it doesn't display the links within the panel. Below is the code for the same.
WebPartZone wz;
WebPartManager wp = WebPartManager.GetCurrentWebPartManager(Page); GenericWebPart gw; wz = this.WebPartZone1;
int countMenu = xmlData.countNodes("/masterpage/left/left_menu/item");

for (int i = 1; i <= countMenu; i++)
{
 Panel pan = new Panel();
pan.ID = "Panel" + i.ToString();
String title = xmlData.GetNodeValue("/masterpage/left/left_menu/item[@id='left_menu_item_" + i + "']/title");
pan.Attributes.Add("title", title);
 pan.Width = 100;
pan.Visible = true;
 int countLinks = xmlData.countNodes("/masterpage/left/left_menu/item[@id=' left_menu_item_" + i + "']/content/content_item");

 for (int j = 1; j <= countLinks; j++)
 {
 HyperLink link = new HyperLink();
link.ID = "hyperlink_" + j.ToString();
 link.Text = "abc";
link.NavigateUrl= "#";
 pan.Controls.Add(link);
 }
 gw = wp.CreateWebPart(pan);
 wp.AddWebPart(gw, wz, (i - 1));
 ((DynamicWebPart)wp).SetDirty();
 }

When I debugged the code I saw that the hyperlinks embedded in the panel are visible in generic web part but they are not visible when I add them to the webpartzone.

Hoping for a reply.

Thanks.
Reply | Email | Modify 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.