Create a basic WebPart

xiaoxiao2021-03-06  61

According to the SPS SDK document, I tried to develop WebPart, the process is like this:

1. Create a project using the WebPart template

2. Define the output path to InterPut / wwwroot / bin.

3, set the version number (every .NET program is done)

4, ready for the key required for strong name, I gave himself a ZHOUYIKEY.SNK, put it in the root directory of the C drive, all the programs need to use it.

5, then start editing the code, first check if the Namespace you need is quoted.

6, define Toolbox Data, such as:

[ToolboxData ("<{0}: SimpleWebPart Runat = Server> ")]

7, define XML Namespace

[XMLROOT (Namespace = "MyWebParts")]

I don't know if all of WebPart can be used by default, but from the documentation, it seems that it is not suitable because XMLRoot uses the global definition, I am worried that if you use the default, there will be conflicts. Therefore, it is best to keep it with the Namespace of the project.

8, then, you can write something you want to display in the renderwebpart method.

9. If you want to create some controls on your WebPart, you must call "Renderchildren (Output) in RenderWebPart, which is the program for creating controls:

Htmlbutton_mybutton;

HTMLINPUTTEXT_MYTEXTBOX;

// Event Handler for _myButton Control That Sets

// 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 Part's 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);

}

转载请注明原文地址:https://www.9cbs.com/read-111078.html

New Post(0)