In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what is the use of ASP.NET pages?" in the operation of actual cases, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
When I talk to developers who are new to ASP.NET pages, the question they usually ask me is: "what on earth is that ViewState?" The feeling in their tone was like the feeling I felt when I came to an exotic restaurant and the waiter served a dish I had never seen before-puzzled and curious. But there must be someone who thinks it's good, otherwise it won't be offered. So, I will taste it first and maybe like it, even though it does look weird!
The same is true for ViewState, but if you adapt to its style, you will find that in many cases you will be happy to use ViewState in your ASP.NET applications because it can help you do more work with less code. However, it is sometimes possible to abandon ViewState altogether. Let's elaborate on each of these two situations, but let's answer the question of what is ViewState first.
Answer: ViewState is used to maintain the UI status of the page
Web is stateless and ASP.NET pages are stateless, and they are instantiated, executed, rendered, and processed on each round trip to the server. As a Web developer, you can add state using well-known techniques, such as storing state on the server in session state, or passing the page back to itself.
This form, like most forms on Web, displays a useful error message and an asterisk next to the field where the error occurs. Also, the form shows all the valid values I entered in other text boxes and drop-down lists. This is possible to some extent because the HTML forms element sends its current value from the browser to the server in the HTTP header.
Before ASP.NET, it was entirely the responsibility of the page developer to restore the value to the form field through multiple postbacks, and they would have to pick up the passed values one by one from the HTTP form and then push them back into the field. Fortunately, ASP.NET can now automate this task, freeing developers from a tiresome task and eliminating the need to write a lot of code for the form. But this is not ViewState.
ViewState is a mechanism that ASP.NET uses to track server control state values that would otherwise not be passed back as part of a HTTP form. For example, text displayed by the Label control is saved in ViewState by default. As a developer, you can bind data or programmatically set the Label only once when the page is loaded, and the label text will be automatically repopulated from the ViewState on subsequent postbacks. Therefore, in addition to reducing tedious work and code, ViewState can usually reduce the number of round trips to the database.
How ViewState works
There is really nothing mysterious about ViewState, which is a hidden form field managed by the ASP.NET page framework. When ASP.NET executes a page, the ViewState value and all controls on that page are collected and formatted into an encoded string, which is then assigned to the value property of the hidden form field (that is). Because the hidden form field is part of the page sent to the client, the ViewState value is temporarily stored in the client's browser. If the client chooses to post the page back to the server, the ViewState string will also be returned. After the postback, the ASP.NET page framework parses the ViewState string and populates the page and individual controls with the ViewState property. The control then uses ViewState data to restore itself to its previous state.
If you want to use ViewState, you must have a server-side form tag () in the ASPX page. Form fields are required so that hidden fields that contain ViewState information can be passed back to the server. Also, the form must be a server-side form so that the ASP.NET page framework can add hidden fields when the page is executed on the server. The page itself stores about 20 bytes of information in ViewState, which is used to distribute PostBack data and ViewState values to the correct control on postback. Therefore, even if the page or application disables ViewState, you can still see a small amount of remaining bytes in ViewState.
In the case where the page is not returned, you can remove the ViewState from the page by omitting the server-side tag.
Make full use of ViewState.
ViewState provides a magical way to track the state of controls across backhaul because it does not use server resources, does not time out, and is suitable for any browser. If you are writing a control, you must need to know how to maintain state in the control.
Developers can also take advantage of ViewState in almost the same way when writing pages, except that sometimes pages contain UI state values that are not stored by the control.
This is the end of the content of "what's the use of the ASP.NET page"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.