Create a basic WebPart

Source: Internet
Author: User
web| to create a document in accordance with the SPS SDK, I tried to develop the WebPart myself, and the process was this:

1. Create a project with a WebPart template

2, define the output path to Interput\wwwroot\bin.

3, set the version number (each. NET program to do)

4, ready to strong name required the key, I got myself a zhouyikey.snk, placed in the C-packing directory, all the program to use it.

5, then began to edit the code, first of all to check their own required namespace have been quoted

6, the definition of toolbox Data, such as:

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

7. Define XML namespace

[XmlRoot (namespace= "Mywebparts")]

I don't know if all of the WebPart is going to be the default, but it doesn't look right from the documentation, because XmlRoot uses the global definition in this way, and I'm worried that if you use the default, there will be conflicts. , so it's best to keep up with the namespace of the project.



8, then, you can write in the RenderWebPart method of what you want to display.



9. If you want to create some controls on your WebPart, you must call "RenderChildren (Output)" In RenderWebPart, and the following is the program that creates the control:

HtmlButton _mybutton;

HtmlInputText _mytextbox;

Event handler for _mybutton control that sets the

Title 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. ";

}

}

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);

}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.