do SharePoint2010 development until recently turned to the 2007 development, I feel there is a lot of development time between the two places is not the same, I'm exposed to 2,007 development projects which use the Module to load Application Page, and in the Application Page wrote a lot of inside background code used to implement business logic, which is rarely used items UserControl and WebPart, that the use of a custom background webpart also Webpart many server controls. Developed over 2010 after seeing this development model suddenly dizzy, felt the development cycle should be relatively slow, or Microsoft in the 2010 version will not join virtual webpart it. Recent practice a little, want to borrow to develop model developed MOSS2010 MOSS2007, today introduce SharePoint2007 WebPart load UserControl. Article belong only to the entry-level, please gurus skipped. . .
SharePoint personally feel there should be as much as possible with UserControl to implement business logic, data presentation, and use WebPart to load these UserControl, then Application Page loaded WebPart, this is just my personal understanding.
Well into the topic, 2007 web part works there is no UserControl, but the web application project which can create UserControl, we can put web app engineering UserControl copy over. So you can build a good one simple framework.
I put the UserControl in ~ / _CONTROLTEMPLAGT / WPUserControls below, CONTROLTEMPLAGT folder is a specialized storage UserControl place, and WPUserControls folder is used to store the project specifically used UserControl.
WebPart engineering framework to build a good note after the Debug attribute modification works, the project deployed to the specified site below.
began to develop a simple UserControl, but in front of the UserControl ascx file should be added to the application of an assembly statement, or after deployment will be reported "Can not load type XXX" error, as shown below:
references to assemblies where the declaration is reflect or site root directory web.config file copy over SafeControl node.
If you want to use the UserControl SharePoint server controls need to quote
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
copied UserControl need to modify the namespace command space I have here is: VeloxWebPart.Templates.CONTROLTEMPLATES.WPUserControls, ascx, ascx.cs and ascx.designer.cs namespace need to be modified.
UserControl created and set up, you need to bind to the usercontrol webpart, the binding code is as follows:
protected override void CreateChildControls()
{
try
{
base.CreateChildControls();
//string strUrl = "~/webParts/WebUserControl1.ascx";
string strUrl = "~/_CONTROLTEMPLATES/WPUserControls/UCTopMenu.ascx";
Control control = this.Page.LoadControl(strUrl);
this.Controls.Add(control);
}
catch (Exception ex)
{
this.Controls.Add(new LiteralControl(ex.Message));
} }
then deploy the entire project will be added to the GAC dll, which added a page to create a webpart, you can see the effects.
course code inside a UserControl allows administrators to enter their own path, that the site administrator can customize the layout of the page. Here late supplement.
没有评论:
发表评论