欢迎光临
我们一直在努力

创建一个基本webpart-.NET教程,数据库应用

建站超值云服务器,限时71元/月

按照sps sdk的文档,我试着自己开发webpart,过程是这样的:

1、使用webpart模板创建一个工程

2、定义输出路径到interput\wwwroot\bin下。

3、设置版本号(每个.net程序都要做的)

4、准备好强名称所需的密钥,我给自己弄了一个zhouyikey.snk,放在c盘根目录下,所有的程序都要用它。

5、接下来就开始编辑代码了,首先检查自己所需的namespace是否都已经引用了

6、定义toolbox data,如:

[toolboxdata("<{0}:simplewebpart runat=server></{0}:simplewebpart>")]

7、定义xml namespace

[xmlroot(namespace="mywebparts")]

我不知道所有的webpart都用默认的可不可以,但是,从文档来看,好像不太合适,因为xmlroot这种方式使用全局的定义,我担心如果都使用默认的是不是就会有冲突。,所以,最好跟工程的namespace一直为好。

8、然后,就可以在renderwebpart方法中写自己要显示的东西了。

9、如果,你要在你的webpart上创建一些控件,你必须在renderwebpart中调用“renderchildren(output);”,下面是创建控件的程序:

htmlbutton _mybutton;

htmlinputtext _mytextbox;

// event handler for _mybutton control that sets the

// title property to the value in _mytextbox control.

public void _mybutton_click (object sender, eventargs e)

{

this.title = _mytextbox.value;

try

{

this.saveproperties=true;

}

catch

{

caption = "error… could not save property.";

}

}

// override the asp.net web.ui.controls.createchildcontrols

// method to create the objects for the web parts controls.

protected override void createchildcontrols ()

{

// create _mytextbox control.

_mytextbox = new htmlinputtext();

_mytextbox.value="";

controls.add(_mytextbox);

// create _mybutton control and wire its event handler.

_mybutton = new htmlbutton();

_mybutton.innertext = "set web part title";

_mybutton.serverclick += new eventhandler (_mybutton_click);

controls.add (_mybutton);

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 创建一个基本webpart-.NET教程,数据库应用
分享到: 更多 (0)

相关推荐

  • 暂无文章