Parameters and values are transmitted between ASP. NET web pages. There are many methods, such as application, Cookie, session, or querystring.
Most of the programs developed by insus. NET are passed parameters and values between the backend, so querystring is rarely used, but session is used. Session? I will. Yes, all programmers who know how to use session to pass Parameters and values.
You can use session to transmit parameters and values between webpages, which can be lightweight or lightweight.
For convenient management of parameters and values, insus. net stores these in a set and transmits them in real time. A category is created in the project.
20 # code is a static method. It has two parameters: dictionary <object, Object> and string URL. The parameter set will be stored in the session for transmission, and the URL is the address of the target webpage. This is simple.
The 30 # And 32 # lines of code are an extension method. It is used to determine whether a parameter set exists when a parameter is added. If yes, you only need to modify the parameter data value.
That's all.
Let's demonstrate it. Create two webpages at the site, pagea. aspx and pageb. aspx. the former completes processing by clicking the button or an event, and transmits some parameters to another page. The latter receives parameters and then performs other logic processing.
Pull a button at pagea. aspx.
These are not important points, but the focus is on the Click Event of the button:
Parameters received in pageb. aspx. CS:
Line 15 and 16, if the user directly enters... /pageb. if aspx is used, the webpage will be directed to pagea. aspx, that is, pageb cannot be accessed directly for the first time. aspx, but needs to first from pagea. after you click the button on aspx, you can access pageb. aspx.
Let's take a look at the demo. The demo transfers the path of the source webpage to the target webpage.
Note that the name of session ["transferobject"] "transferobject" must be the same as the name of the session in the insusbase. transferparameter () method that was originally created.
Is there any improvement, so you don't have to remember such multiple session parameter names during development? There are methods. Here is what insus. Net needs to solve.
Enable the insusbase. CS category in three steps:
On the webpage receiving parameters, use static attributes to replace the parameter names of sessions and sessions. This solves the problems mentioned above.