A new generation of visual Studio 2010 has been written about SharePoint 2010, and has been greatly praised. I used to write a WebPart to do a lot of seven miscellaneous eight steps, but also hard to write HTML output, when someone said can write UserControl and then hang in other WebPart container, but also have to take a lot of time to deal with it. Now that these questions are gone, a few simple steps can make a powerful webpart, and the method of detection is very simple.
A new generation of visual Studio 2010 has been written about SharePoint 2010, and has been greatly praised. I used to write a WebPart to do a lot of seven miscellaneous eight steps, but also hard to write HTML output, when someone said can write UserControl and then hang in other WebPart container, but also have to take a lot of time to deal with it. Now that these questions are gone, a few simple steps can make a powerful webpart, and the method of detection is very simple.
First, in Visual Studio, select Add a SharePoint 2010 Visual WebPart case,
Next, choose a SharePoint 2010 site to test for, where you can choose SharePoint 2010 on your machine to make it easier to detect bugs. Or maybe you'll ask, that doesn't require visual Studio 2010 to be installed on Windows Server, and the new version of SharePoint 2010 can be installed on Windows 7, which is convenient for developers.
After entering the editing screen, select the ascx and switch to the design screen, and we can drag and drop the controls inside the Toolbox onto the canvas, where we put a button and a GridView control, and I'll name the button btndatetime, The GridView name is Gvresult, I want to do the demo is to press the button, the GridView inside the new pen to press the time information displayed on the top. So next, on the button press two, we can write code behind's event-based function. Of course, we're going to have a list to store the time information and put it in viewstate. So in the Page_Load event wrote a ispostback sentence, not ispostback the viewstate["Data" to build up, Type is list<datetime> Then in the Btndatetime_click event, add the value of DateTime.Now to the viewstate["Data", then use LINQ to sort the information, the new information on the top, when doing Gvresult datasource, Do DataBind ().
After the code is written, directly press the Execute button on the function sheet to execute the line, we can also set the point, let the WebPart run, can stop to detect wrong. The first vistual Studio 2010 will ask you if you want to open the Web. config bug Here we choose to open, and then you'll see that the SharePoint 2010 Web site is also open.
After the website is opened, we need to go into the edit mode and then add the WebPart that we just made. The new WebPart is temporarily placed in the custom category.
After adding a new WebPart, we can press the button that we just made, and this time the program will stop at the point in Visual Studio 2010 and let us do the wrong thing. We can cancel the break, press the button repeatedly, and we'll see the time of the material being added to the pen. "
Is it simple to finish a WebPart. Of course it's just a test on the development of the environment, and then the packaging and deployment to the formal environment, there are a few details to be aware that the Department of Visual Studio has helped us prepare, we can change the folder under the feature to name, as we want to show the feature name, And then go in to modify the items that feature to include and activate, where we only have a WebPart that describes the information element.xml for the WebPart installation. Both the WebPart file and the ascx file will be ready, then select the feature range to site, and then adjust the package's internal WSP file, you can edit the WSP file, get a formal environment to activate. You can say that compared to SharePoint 2007 is an easy one. Also believe that the launch of SharePoint 2010 for ASP. NET developers will become more relaxed and enjoyable.
[SharePoint 2010] Visual Studio 2010 in-writing visualization WebPart Super simple