ASP Network programming: Control Web pages on the server side

Source: Internet
Author: User

Use. NET and C # developing Web applications can often give us a lot of inspiration, especially when developing relatively simple routine tasks. For example, in many cases, we need to conditionally display part of a Web page. There are many reasons to do this, for example, depending on the role of the user, there is a part of it that should not be seen. Alternatively, we can also consider the search function, which is available only when a link is clicked.

Let's first explain how to solve this problem, and then explain the code in detail. To develop Web applications in. NET, we can use both server-side Web controls (Web Forms) and HTML controls. Use. NET development of Web applications is focused on server-side controls. We have used Web Form server-side controls in this article.

A panel is a server-side Web Form control, and a panel control is a rectangular area on an HTML page that can be visible and controlled on the server side. So, first, we can put the HTML snippet in a panel control, and the HTML snippet can be made up of server-side controls and client controls. Once we set the visibility property of the Panel control to "false", the entire HTML snippet becomes invisible. Second, we can use another Web Form control named LinkButton, which is essentially a hyperlink, but through the server-side OnClick method, it can play the role of a button. In this approach, the Web page automatically refreshes itself simply by accessing the C # language representation of the Panel object and setting its Visibility property to true or false.

One important difference in developing Web applications in. NET is that each control on a Web page is represented as one on the server side. NET objects, and the state of these objects (controls) is maintained through multiple interactions with the server, which enables us to react to server-side and client events. In response to server-side events, when hundreds of pages are refreshed, all objects (controls) inside them are refreshed. We don't have to draw any more controls, and all of this is done automatically. One of the most attractive aspects of this approach is that a good object-oriented programmer can work in a programming language mode, and it's easy to debug with JavaScript. A small problem with this approach is that it cannot use HTML code editors such as FrontPage or Dreamweaver. Once this problem has been solved, the server-side programming model is more complete.

Here are the steps required to write the example code in this article:

• Get the Panel control for the HTML code snippet.

• Place the HTML code into the Panel control.

• Create a LinkButton control.

• Provide an onclick function.

• Hide/show the Panel control in the Click function of the button.

1. Get the Panel control for the HTML code snippet

Open the Design view of the Web page (. aspx) and select the WebForms Control Toolbox to drag a Panel control from the Toolbox to the Design view of the HTML page. You will then see a rectangular box that changes its size until it can tolerate the HTML snippet you want to enter.

The following is the definition of the Panel control in HTML Design view:

HTML GOES Here

2. Enter our HTML code into the Panel control

To write the relevant HTML code in the Panel control (or drag the HTML code into the Panel control), here's an example:

An

example HTML segment

that's going to disappear

A example drop down

3. Create a LinkButton control

We need to make some explanations for this part. Why do we use the LinkButton control instead of a hyperlink? Hyperlinks mean we are free to go to any page that includes the current page, but that doesn't mean we're going to go back to the page we're modifying. In addition, there is no server-side approach like onclick that can handle hyperlinks.

The LinkButton has the same appearance and style as the hyperlink, but it has another two benefits, namely:

• Ability to return to the same page when clicked.

• Easy-to-use OnClick method.

The following is an example of a LinkButton control definition:

Change appearance

4. Provide the OnClick function

If you double-click the LinkButton control, the IDE automatically leads us to the server-side OnClick method of the control, where we can write code that hides the Panel control.

5. Hide/Show the Panel control in the button's OnClick method

Here is an example of the OnClick method:

private void Changeappearancebutton_click (object sender, System.EventArgs e)

{

This. Testpanel.visible = this. Testpanel.visible? False:true;

}

The above code is an excellent example of how to maintain a product-side programming pattern for your state. When the user clicks on the link, the code is executed, but the developer does not change the rest of the HTML page, and the control itself knows how to refresh itself.

Conclusion

Here's what I'm from. The very interesting features that are featured in the net pattern:

• Server-side programming mode.

· The state of the Web form is automatically maintained.

• Highly consistent front-and back-end unified object programming model.

• A very useful IDE can prompt for each method and possible parameters.

• Writing XML code in the HTML view of a Web page is also a hint.

• Configure the required unified Web. config.

Although the examples in this article are fairly simple, even using traditional methods can be implemented very simply, this server-side programming model illustrates an interesting feature of net, a consistent, unified server-side programming model that automatically maintains its state. Shanghai Male Hospital editor reminds readers if they do not understand can contact me oh.

ASP Network programming: Control Web pages on the server side

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.