If (! Page. ispostback) Errors
1. Incorrect verification code
The verification code is generally generated directly in the page_load event or by calling a function. If you do not generate the verification code Code Put it in if (! Page. ispostback), when you click the login button, you will never be able to log on. You carefully check and find that the login code is not, but you cannot log on. If you track, you will find that, the verification code and Program The generated verification code will be different, but when you log on, you clearly fill in the correct verification code. Haha, this problem will be dizzy if you have no experience. Here, I will explain why the verification code is different when you click Login.
When you click the login button, most people think that the event code of the login button will be directly executed. In fact, the error is here. When you click Login, the first code of page_load is executed, that is, no matter when you click the button, the code in the page_load event is executed first, and then the Event code corresponding to the button is executed, because it executes the code in page_load, the verification code is re-generated, and the verification code you entered will not change. Result 1 compares two verification codes (one you entered, ), of course it is different. To solve this problem, you only need to place the code that generates the verification code in if (! Page. ispostback) can be solved. After you put it in it, when you view the page, click the login button and the code will no longer be executed.
2. You cannot get the value of the drop-down menu.
Generally, the content in the dropdownlist control is added through code in page_load. If the code is not put in if (! Page. in ispostback), when you click the login button, the content in the drop-down menu will be re-generated, so no matter which one you choose, you can only get the first value, the solution is the same as the above problem. The principle is the same. I will not explain it here.
Example
Code
1 Using System;
2 Using System. Data;
3 Using System. configuration;
4 Using System. Web;
5 Using System. Web. Security;
6 Using System. Web. UI;
7 Using System. Web. UI. webcontrols;
8 Using System. Web. UI. webcontrols. webparts;
9 Using System. Web. UI. htmlcontrols;
10 Public Partial Class _ Default: system. Web. UI. Page
11 {
12 Protected Void Page_load ( Object Sender, eventargs E)
13 {
14 If ( ! Ispostback)
15 {
16 This . Label1.text = Datetime. Now. tolongdatestring ();
17 This . Panel2.visible = False ;
18
19 }
20 }
21 Protected Void Button#click ( Object Sender, eventargs E)
22 {
23 If ( This . Textbox1.text. Trim () ! = "" )
24 {
25 Response. Redirect ( " Default2.aspx? Username = " + Textbox1.text. Trim ());
26 }
27
28 }
29 Protected Void Linkbutton#click ( Object Sender, eventargs E)
30 {
31 This . Panel1.visible = False ;
32 This . Panel2.visible = True ;
33 }
34 }
35
36 Default2.aspx content
37 Using System;
38 Using System. Data;
39 Using System. configuration;
40 Using System. collections;
41 Using System. Web;
42 Using System. Web. Security;
43 Using System. Web. UI;
44 Using System. Web. UI. webcontrols;
45 Using System. Web. UI. webcontrols. webparts;
46 Using System. Web. UI. htmlcontrols;
47 Public Partial Class Default2: system. Web. UI. Page
48 {
49 Protected Void Page_load ( Object Sender, eventargs E)
50 {
51 If (Request [ " Username " ] ! = Null )
52 {
53 This . Label1.text = Request [ " Username " ]. Tostring ();
54 }
55
56 }
57 }
58