Tutorial 3 (Answer)
Tutorial 3 (Answer)
Chapter 3
Tutorial 3 (Solution)
1. An event is an action taken on your application by some force outside of your code. This external force is usually the user, but could be another program. An event can hold that will run when the action occurs. An event handler is a method thats called when a specified event occurs. An event handler must be declared with Public or Protected scope. A function or method containing program statements that are executed in response to an event. An event handler typically is a software routine that processes actions such as keystrokes and mouse movements. With Web sites, event handlers make Web content dynamic. JavaScript is a common method of scripting event handlers for Web content. (www.webopedia.com) Its a good way of programming because much more work is automatically performed for us. Great range of events available to improve the user experience reduces the amount of code, and codes are easier to maintain. 2. HTML Event onmouseup onmousedown onmouseover onmousemove onclick ondbclick onkeyup onkeypress onkeydown 3. ASP.NET Server Control Event ondatabinding ondispose onload onunload oninit onprerender
Chapter 3
4(a). Answer depends on students justifications. She/he needs to compare which one is better. Server-side event handler: Upside can execute the event handler code on the server, which means that you have all the server resource available for the event handler. This includes custom-built objects and connection to other servers and databases dont have to rely on the browsers capability to recognize and handle HTML events because the ASP.NET Web server sends only pure HTML back to the browser. can write code for an event handler in any language that is supported by .NET instead of just the scripting language that browsers can execute. Downside Information is post back and handled by server, and therefore server reacts to the event slower, i.e. could not react to the users action as quickly as expected. (high CPU and bandwidth costs are high) Client-side event handler: Upside: An interpreter built into the browser executes the code and there is no transfer of information to or action on the part of the server. (Performance is faster) Downside: Harder to code (use JavaScript, VBScript, or Java applets) (example: data manipulation is harder) Harder to support multiple/older browsers (e.g. not all old browser supports JavaScript) 4(b). Some events need quick response to the user, such as pop-up dialog box, or form validation that typically run on client-side JavaScript/VBScript. So we still need a mix of server-side and client-side event functions in the Web application. 5. HTTP is stateless, meaning that it retains no knowledge from one request to the next. So, when user request a page from a web server, the page is sent to user and the server immediately forgets everything about you; each request stand alone. When postback is used, information about the state of the ASP.NET form is sent back in an associated hidden control _VIEWSTATE. Information (value) in _VIEWSTATE is generated by ASP.NET by encrypting the values of the old state of the form (e.g. user selections for each Web control).With this information, ASP.NET can persist the state between page submissions.
6.
Chapter 3
7.
Source code in the Page_Load event handler executes every time the ASP.NET web page is requested. When the user visits the page for the first time, she has yet to enter the loan amount, interest rate and total number of month. Therefore, in attempting to compute the calculation, we will get an error. Specifically, the code will try to perform numerical calculations on a user-inputted value that has yet to be provided. Because we want to perform the calculation only after user has provided the required inputs, the source code for the calculation is placed in the Button_Click event handler.