WebMatrix develops ASP.NET trial

xiaoxiao2021-03-05  25

Foreword undeniable, Microsoft's heavyweight development tool Visual Studio.net really provides us with a very powerful, excellent .NET application system integration development environment. However, it is also possible to face some questions using VS.Net, such as: vs.net pay (of course, the D version is another matter), vs.net installation is more troublesome, VS.NET is very space, the machine requirements are also higher. . Therefore, using VS.NET to develop a relatively high use cost, there is only a good sexual performance ratio for large system development. If you just want to make a small and medium-sized ASP-based web application development, do you have to use powerful and expensive Visual Studio.net? the answer is negative. Recently Microsoft provides developers with a free small and easy-to-use development ASP.NET tool, which is WebMatrix. Figure 1: http://www.asp.net/webmatrix Figure 1 is the homepage of the WebMatrix project, WebMatrix originated in December 2000, Microsoft engineers were fully utilized for a free lightweight development of .NET Framework and C # language ASP.NET Rapid Development Tools can be easily and easily completes the development of web application systems. WebMatrix's most prominent feature is small and flexible. The entire installation file is about 1.3m, and all the size is just 2.8m after installation. It is only necessary to basic .NET Framework support, and even do not need to install IIS because WebMatrix With a Microsoft ASP.NET Web Matrix Server, you can release the ASP.NET application. WEBMATRIX L) Installing WebMatrix WebMatrix The operating system currently supported is Windows 2000 and Windows XP, which can be downloaded from http://www.asp.net/webmatrix/. Microsoft .NET Framework 1.1 and Internet ExpleroR5.5 or more are required before installing WebMatrix. The installation process is a fool, only the "next" is all the way. After installing, run can see the main interface of WebMatrix, as shown in Figure 2. Its interface layout is a bit similar to vs.net. The upper part is a menu / toolbar. The left is a toolbox, providing various control tools required to develop ASP.NET, and the right side is the workspace management bar and attribute column, which is used for files / The data management and control properties are configured, and the middle is the main work area. Figure 2: WebMatrix Main Interface 2) First ASP.NET Program Hello WebMatrix! First let's create the first ASP.NET program, create a new file from the FILE menu, you can see a new file dialog (Figure 3). Figure 3: New file dialog WebMatrix and vs.net is a great difference between WebMatrix based on files, rather than being managed based on projects (Project) as VS.NET. This is a small and medium-sized project, which is relatively simple in small and medium-sized projects. Small project development is relatively simple. It is not so complicated. WebMatrix itself is just a lightweight development tool. From the open new file dialog box, you can see that WebMatrix supports newly built multiple types of files, including .aspx, .sql, .cs, .xml file, etc., you can support three typical .NET application development languages ​​- C #, J #, Visual Basic.net.

Select the default ASP.NET page and enter the file name HelloWebMatrix.aspx you want to create. Select C # to programmatically, you can create a blank ASPX page file. WebMatrix provides four views for each ASP.NET file window, namely Design, Static Code View (HTML), Dynamic Code View, and Global View (ALL), default display is a design view . From the Web Controls column in the left toolbox, select the Button control to drag and drop to the page design view, you can see that a Button control is displayed in the view, modify its text attribute to "Greetings!" In the properties column, you can see The text on the button becomes "greetings!", As shown in Figure 4. You can see the default name of the control from the properties column of the interface to Button1. Figure 4: Add the visual editing of the HelloWebMatrix program to the view area, then start editing the code. Double-click the "Greetings!" Button in the view area, you can see that the page view area is turned to the Code view by the Design view, and the WebMatrix automatically creates a function to the Button1 Click event --void Button1_Click (Object Sender, EventArgs E), functions The body has no content. Add a line of code in the function body: "Button1.text =" Hello WebMatrix! "The entire development process is completed, as shown in Figure 5. Figure 5: Add a processing code to the button Click event Click the Run button on the toolbar to run Program, you can see a dialog box that pops up, asking if IIS or comes with Web Matrix Server, if IIS is installed on the machine, you can select its default web matrix server, enter a book in the port number. The machine is idle port number, such as 8000, click the start button to start running, as shown in Figure 6. Figure 6: Select the running server of the ASP.NET application first launched the Web Matrix Server during operation (you can see the Windows system tray) An icon appears in the district), then you can see a "Greetile" button on the page from the pop-up browser window, click the text on the button "Hello Webmatrix! "As shown in Figure 7. Figure 7: HelloWebMatrix program Running effect development database access program dynamic web development is the development database access program .Webmatrix provides a good support for developing ASP.NET database access programs. Observe A workspace management bar (Workspace) of the main area of ​​the WebMatrix main interface, will find a DATA tab next to the Workspace tab, here also provides a data bar (DATA), click the DATA tab to enter the data window. (DATA) Figure 8. Figure 8: Data Window Development Database Access Procedure To create a database connection, click Add Database Connection button in the Data window to see the added new database connection project window, as shown in Figure 9 .

Figure 9: Adding Database Connection WebMatrix can support Access database, you can also support SQL Server / MSDE Database / Desktop Engine. If it is the latter, you can get better support. Here you can choose Access Database, click OK. From the pop-up dialog box, select an Access database, such as the Sample Database that comes with Access: Home member address database file addrbook.mdb, you can see that WebMatrix has built a database connection in the data window, from See the data table in the database, as shown in Figure 10. Figure 10: After the establishment of a good data connection is built after the database connection, the remaining things is simple, create a new ASP.NET program file DatabaseAccess.aspx, then select a data table in the Data window (such as "family member" Table) Drag and drop to the page design view, you can see a MXDataGrid control and an AccessDataSourceControl control on the page, and automatically complete the association of the data set, as shown in Figure 11. Figure 11: Drag and drop a data sheet to the page design view area The effect has completed the development of a database access program with basic data display capabilities. Click the Run button to run the program, you can see the display effect of the page - displayed a data sheet for home member information, you can see that this data table has also been automatically paging display processing, the last line of the table is data The page number link displayed by the page, click on the table of the table with the mouse, and the data can be sorted by this column, such a data table is already able to meet the general page data display, and you have not even written a line yet. Code. Figure 12: Database Access Program Run as a database access program, only data display function is of course not enough, you also need to add some basic increase, delete, modified interaction, and we add data query function for the DatabaseAccess program. Back to the page design view, drag and drop the TextBox and Button in the WebControls bar to the page design view from the toolbox, set the button "Text" property to "Query", and drag and drop a DataGrid control to the next line. As shown in Figure 13. It can be seen that the names of these controls are set to TextBox1, DataGrid1, button1. Figure 13: Adding a query text box and button This time the program's page visual design is complete, then implement a function of the member's last name in the text box in the text box (delete, modification function can be implemented in a similar manner) . Click the Code tab in the bottom of the page view, the page view area goes to the Code view, you can see the Code Wizard in the toolbox on the left side of the WebMatrix interface, as shown in Figure 14. Figure 14: The Code Wizard can see "Code Wizard" provides several basic data operations (such as SELECT, INSERT, DELETE, UPDATE, etc.) Code Wizard, double-click "Select Data Method", you can see the screen pops up one Query Code Add Wizard dialog, as shown in Figure 15.

Figure 15: The Query Code Add Wizard dialog is operated in accordance with the wizard sequence, 1) Select the database (ADDRBOOK.MDB) to perform query operation, as shown in Figure 15; 2) Select the data item to be displayed in the query result (member number, Name, last name, role, etc.), as shown in Figure 16; Figure 16: Selecting data items to be displayed in query results 3) Click the WHERE button, select the data items and query conditions (last name) to query, as shown in Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17; Figure 17 : Select Data Items and Query Conditions to Query and Query Conditions 4 After completing the settings, click the Next button to enter the Query Test dialog box, click the Test Query button to check the query test, enter the number "Zhao", you can see that the member information of the last name Zhao is displayed, This shows the success of the test, as shown in Figure 18; Figure 18: Test Query Result 5) Final setting the name of the generated query method (default as myQueryMethod) and return type (default Dataset), as shown in Figure 19; Figure 19: Set generation Query Method Name and Return Type 6) After the setting is completed back to the Code view, you can see the virtueryMethod method source code that WebMatrix automatically generated, as shown in Figure 20. Figure 20: The generated query method source code is next to the last step, associating the click event of the query button with the query method. Click on the Design tab at the bottom of the page view area to return to the Design view, double-click the "Query" button to add to the page, you can see the page view area to the CODE view by the Design view, WebMatrix automatically uses the Click event of the "Query" button. Created a function -void button1_click (Object Sender, Eventargs E), the function body has no content. Add two lines of code in the function body:

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

New Post(0)