100 likes | 214 Views
MIS 3200 – Unit 3.2. Page_Load method AutoPostBack property of controls IsPostBack method of the Page object Understanding web page life cycle. Page_Load Method. Handles the page_load event It occurs when Page is loaded for the first time
E N D
MIS 3200 – Unit 3.2 • Page_Load method • AutoPostBackproperty of controls • IsPostBack method of the Page object • Understanding web page life cycle
Page_Load Method • Handles the page_load event • It occurs when • Page is loaded for the first time • a web control with AutoPostBack = true is run • Sends contents of the page back to the server
AutoPostBack Property • Is a Boolean property of a web control • causes page information to be sent back to server • tells the server that the page is “posting back” • i.e. Page.IsPostback gets set to TRUE • Example: in U3L2 you set the AutoPostBack = true • As a result, whenever it was changed, it “posted back” to the server, and • Told the server that this was not first request about that page , but was a post back.
IsPostBack • Is a Boolean property of the Page • Used inside the Page_Load method • e.g. Page.IsPostBack • FALSE: when page is loaded for the first time • TRUE: when the user interacts with the page • E.g. clicks a button • E.g. changes a radio button that has AutoPostBack=TRUE
IsPostBack: Usage Example 1 Knowing if the IsPostBack property of the Page object is true or false can allow you to determine which messages should be displayed:
IsPostBack: Usage Example 2 Same code as the previous slide, written with an if else statement:
The life of a web page 1st – client requests page IsPostback= false Page_Load runs Page_Load runs 2nd – server sends page (empty form) 3rd – responses (filled form) sent to server IsPostback= true 4th– server sends page (results)
Equal or not! In Unit 3.1, we looked at relational operators and were introduced to the idea of saying something was not equal by using the ! (exclamation mark) If we want to test a condition, we could say if (condition != true) do something; if (condition == false) //same as != true do something;
Q Page_Load: IsPostBack One more example of the same code written with an if else statement, but this time using the ! (not) operator:
Think About It! • What does AutoPostBack do? • How do you test IsPostBack? • What does !Page.IsPostBack mean?