共同学习SPS,掌握Csgl#,FireScript孵化纪实

——基于.NET脚本解释引擎,可以用于ASP.NET,WinForm,WebServices

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

安装SPS的过程非常顺利,这里就不说了!
我来制作自己的第一个webpart!
1.请先安装Web Part Templates for Visual Studio .NET 下载
2.安装好以后,打开VS.NET 2003。在新增项目的对话框中找到Web Part Library,新增一个webPart,我取名[FlWebPart1],新生成的代码如下:
t_webPart1.bmp点此看大图
3.编译生成的FlWebPart1.dll就是我们的第一个WebPart。好了,按照网上的资料我作个如下改动:

 1protected override void CreateChildControls()
 2        {
 3             myUserControl =     this.Page.LoadControl("/bin/myWebPart1.ascx");
 4            base.CreateChildControls ();
 5        }

 6
 7        
 8        /// 
 9        /// Render this Web Part to the output parameter specified.
10        /// 

11        ///  The HTML writer to write out to 

12        protected override void RenderWebPart(HtmlTextWriter output)
13        {
14            this.EnsureChildControls();
15            output.Write(SPEncode.HtmlEncode(Text));
16            if ( myUserControl != null )
17            {
18            myUserControl.RenderControl(output);
19            }

20        
21        }

4.在代码中你一定看到了一个"/bin/myWebPart1.ascx",这个其实就是一个传统的Web UserControl,跟它相关的.cs文件是webpart不需要的(ps:有几头牛上一这么说的)。怎么把UserControl跟.cs文件脱离呢:
   <%@ Control Language="c#" AutoEventWireup="false" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <%@ Control Language="c#" AutoEventWireup="false" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <%@ Control Language="c#" AutoEventWireup="false" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> 

<%@ Control Language="c#" AutoEventWireup="false" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <%@ Control Language="c#" AutoEventWireup="false"   TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<%@ Control Language="c#" AutoEventWireup="false"   TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>

看去掉Codebehind, Inherits属性就可以了。
5.在UserControl控件中拖入各种控件,我拖的是微软日历控件
6.重新编译WebPart项目。

 

posted on 2005-10-14 16:24  FireReprt◇FireScript地带  阅读(524)  评论(2编辑  收藏  举报