Blue Theme Orange Theme Green Theme Red Theme
 
HeaderAd
Home | Forums | Videos | Photos | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article 
 Login Close
User Id:
Password:
 
Forgot Password
Forgot Username
Why Register
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
 Resources  
Close
 Our Network  
Close
Search :       Advanced Search »
Home » ASP.NET 2.0/3.5 » 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:
Technologies: .NET Compact Framework, ASP.NET 1.0,Visual C# .NET
Total downloads : 159
Total page views :  13238
Rating :
 0/5
This article has been rated :  0 times
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
TestPart.zip
 
ArticleAd
Become a Sponsor



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


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 Gommunication Foundation
Appl ication Developmen, software Developer/ project lead with 8 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 sites connected to a SQL database. He has focused on Asp.Net, C#, vb.net and SQL Server development. He had worked on payment gateway implementation. He is experienced in Insurance, Supply Chain management, Trading, Real-Estate & currently Legacy moderanization domain.
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.
Boost the performance of your .NET applications
“ANTS Profiler took us straight to the specific areas of our code which were the cause of our performance issues." Terry Phillips, Sr. Developer, Harley-Davidson Dealer Systems. Download your free trial of ANTS Profiler.
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today.  With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications.  Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
 
   Print Read/Post comments Post a comment  Rate  
   Email to a friend  Bookmark  Similar Articles  Author's other articles  
Download Files:
TestPart.zip
 
 Post a Feedback, Comment, or Question about this article
Subject:  
Comment:  
ArticleAd
Become a Sponsor
Latest Comments:
Subject Posted By Posted On
Dynamically adding hyperlinks to a panel which is added into the webpartZainab1/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 | Delete | Modify | 

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved