Location via proxy:
[ UP ]
[Report a bug]
[Manage cookies]
No cookies
No scripts
No ads
No referrer
Show this form
Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Loading...
Loading...
User Settings
close menu
Welcome to Scribd!
Upload
Read for free
FAQ and support
Language (EN)
Sign in
1 Wap
Uploaded by
krpal204
0 ratings
0% found this document useful (0 votes)
3 views
30 pages
AI-enhanced title
Document Information
click to expand document information
1Wap material
Original Title
1wap
Copyright
© © All Rights Reserved
Available Formats
PDF or read online from Scribd
Share this document
Share or Embed Document
Sharing Options
Share on Facebook, opens a new window
Facebook
Share on Twitter, opens a new window
Twitter
Share on LinkedIn, opens a new window
LinkedIn
Share with Email, opens mail client
Email
Copy link
Copy link
Did you find this document useful?
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Is this content inappropriate?
Report this Document
1Wap material
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF or read online from Scribd
Flag for inappropriate content
Download now
Download as pdf
Save
Save 1wap For Later
0 ratings
0% found this document useful (0 votes)
3 views
30 pages
1 Wap
Uploaded by
krpal204
AI-enhanced title
1Wap material
Copyright:
© All Rights Reserved
Available Formats
Download
as PDF or read online from Scribd
Flag for inappropriate content
Save
Save 1wap For Later
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Embed
Share
Print
Download now
Download as pdf
Jump to Page
You are on page 1
of 30
Search inside document
Unit2 Web Form Fundamentals Templates to create ASP.NET applications vi. ASP.NET Web Forms Site: A ready-made website with a main layout page, a home page, an about page, and user account pages (register, login, change password). ASP.NET Web Site (Razor): A website using the MVC (Model-View-Controller) pattern, giving you more control over IITML and better for testing. ASP.NET Empty Web Site: A basic website with only a configuration file, great for learning ASP.NET without extra files. ASP.NET Dynamic Data Entities Web Site: A website that easily connects to a database using dynamic data features. WCF Service: A set of server methods that other programs can call. ASP.NET Reports Web Site: A webs online, for creating and viewing database reports 4.2.2 Anatomy of a Webform Views of a WebForm: Design View: Drag and drop components from the toolbox and adjust their appearance and layout. Source View: Sec and edit the underlying HTML and ASP.NET control tags, Code-Behind File (.aspx.cs): Write dynamic and operational code for the web form. Key Parts of a WebForm: a) Directives: Control page compilation, navigation settings, error fixing, and class importing. Directives start with <%@ and end with %=. Example: <%@ Page Language="C#" %> specifies the programming language (C# or VB.NET) for the page. b) Doctype: Appears just below the page directive. Indicates the type of markup (HTML, XHTML) used for the web page. Influences how the browser interprets the page. Example: ¢) Web Form Markup: + Contains standard HTML tags like , , and . + Can include additional HTML elements such as paragraphs, headings, tables, etc. + Allows adding ASP.NET-specific elements. + Example:
adds a label By understanding these parts, you can effectively design and code your ASP.NET web forms. 4.3 Writing Code + To write dynamic or operational code, switch to the code-behind view. + Use the View Code or View Designer buttons above the Solution Explorer. + You can also double-click the .aspx page (for design view) or the .aspx.cs page (for code view) 1. Code-Behind Class: + Code-behind is the code for an ASP.NET page written in a separate .cs file. + Ithandles events and other functions required for the page. 2. Adding Event Handlers: + ASP.NET uses an event-based model. + Example: Add a button to a Web Forms page and write a click event handler for it. + Events vriginate ui Ue client sidle but aie havadled uns Ube set ver by ASP.NET. + Event-handler methods follow a standard NET Framework pattern: © They pass two arguments * An object representing the source of the event. + Anevent object containing event-specific information, Syntax: _ private void EventName( object sender, EventArgs e ); where, object sender represents the object raising the event EventArgs represents the event arguments Ex. Select the button and right click and click on properties. In the properties window click the yellow icon event.Or simply double click the button, it will show code behind file where we can write the code if the user click button what action has to be performed. public partial class Default : System.Web.ULPage { protected void Page_Load (object sender, EventArgs ¢) { } protected void Button1_Click(object sender, EventArgs ¢) { } t @ Class Definition: + public partial class_Default :System.Web.UI.Page: This line means we are creating ‘a web page class named _Default. © Page_Luad Methud: + protected void Page_Load(object sender, EventArgs e): This method runs every time the page loads. + You can put code here to set up things when the page is first opened. @ Button1_Click Method: «protected void Button _Click(object sender, EventArgs e): This method runs when the button named Button1 is clicked. + You can put code here to define what should happen when the button is pressed. 4.4 Understanding the Anatomy of an ASP.NET Application + ASP.NET applications are divided into multiple web pages. + Allpages share common resources and configuration settings. + Each application runs in its own space, ensuring that errors in one application don't affect others.Key ASP.NET File Types ‘+ aspx: ASP.NET web pages containing the user interface. + .asex: User controls, reusable parts o' the user interface, without , , and
tags. mx: Web services for creating APIs. + web.config: XML-based configuration file managing security, state, and memory. + global.asax: Defines global variablesand handles global events. + disco or .vsdisco: Discovery files for locating web services. + vb or cs. Code-beliind files separating code from the user interface. + sin, suo: Visual Studio files grouping projects during development. Special ASP.NET Web Folders + App_Browsers: Stores browser definition files (browser) to support different browsers and mobile applications. + App_Code: Contains source code files (.cs, .vb) for utility classes and business logic, automatically compiled. + App_Data: Stores database files (.mdf, xml) for local data storage. + App_GlobalResources: Holds global resource files (.resx, resources) for text and images, supporting multiple languages. + App_LocalResources: Contains resource files for specific pages or controls, not globally accessible. + App_Themes: Includes subfolders defining themes (look and feel) with files like skin, css, and images. + App_WebReferences: Stores web reference files (.wsdl, .xsd, isco) for web services. + Bin: Contains compiled assemblies (dll) automatically referenced by the application. 4.5 Introducing Server Controls Server controls are elements on an ASP.NET page that users can interact with. They handle tasks like displaying data, capturing user put, and validating information. ‘Types of Server Controls 1, HTML Server Controls: © These are traditional HTML tags with added functionality. For example,
turns a regular HTML input field into a server control. 2. Web Server Controls: © These are ASP.NET-specific controls that provide richer functionality. Examples include
and
. They are more powerful than regular HTML controls. 3, Validation Server Controls:© Used to check user input for correctness. Examples include
and
. They help ensure the data entered by users is valid before it is processed. Key Points + Within
: Most server controls need to be inside a
tag to function properly. Exceptions include the
and
. + Advantages. © Access and State: Server controls make it easy to interact with HTML elements in your code. They retain their state, so user inputs are preserved across postbacks (when a page is sent to the server and then returned to the client). © Separation of Concerns: ASP.NET controls help separate the design (HTML) from the logic (C# or VB.NET), making it easier to manage and maintain your code. 4.5.1 HTML Server Controls ‘The HTML server controls are usually considered as the standard HTML controls which are created to enable server side processing. When attribute runat="server" is added, they get converted into server control and when is attributed is added, they are available for server-side processing. All HTML server controls must be within a
tag with the runat="server" attribute. ASP.NET requires that all HTML elements must be properly closed and properly nested. HtmlAnchor: Controls an
HTML element (link), HtmlButton: Controls a
HTML element. HemlForm: Controls a
HTML element. HtmiGeneric: Controls generic HTML elements like ,
,
. Htmllmage: Controls an
HTML element. HtmllnputButton: Controls
,
, and
el HtmlInputCheckBox: Controls an
element. HtmlInputFile: Controls an
element. HtmlInputHidden: Controls an
element. HtmlInputImage: Controls an
element. HtmlInputRadioButton: Controls an
element. HtmlInputText: Controls
and
elements. HtmiSelect: Controls a
HTML element (dropdown list). HtmiTable: Controls a
HTML element. HtmITableCell: Controls
and
HTML elements (table cells and headers), HtmiTableRow: Controls a
HTML element (table row). HtmlTextArea: Controls a
HTML element. EX.This example has 2 text boxes which accepts user input as Name and Age. One button to perform action and one label to show result. Detaultaspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
head run: <
MyPage
fica
‘unat="server"> Name:
Age:
S [Otocathost3965/0e8.. ]O # Apps @_ latest hollywood hir Pe ‘Yashashree is 6 years old. 45.2 View State ViewState maintains the state of a web page between postbacks (when a form is submitted and then reloaded) to ensure the page's contents remain unchanged. It does this by storing the values of page controls (such as text boxes and dropdowns) ina hidden field on the page. How It Functions + Saving Data: As the page is rendered, ViewState stores the current values of controls in a hidden field on the page. + Restoring Data: When the page is submitted and sent back to the server, ViewState retrieves these stored values and restores them to the controls. Advantages 1. No Server Resources Required: ViewState data is stored on the client side, eliminating the need for server memory usage 2, Enhanced Security: Data within ViewState is encrypted, providing protection tor sensitive information. 3. Ease of Use: ViewState is straightforward to manage; you can enable or disable it for individual controls as needed. 4. Flexibility: Developers have the option to apply ViewState at either the page level or the wontsol level. Disadvantages 1. Increased Page Size: arge amounts of data in ViewState can make the page size bigger, which might slow down page loading. 2. No Cross-Page Tracking: ViewState data is specific to a single page and does not. automatically transfer to other pages. HTML: <%@ Page Language="C#" %>
C# Code-Behind: public partial clase Default : Syctom.Web.ULPage { protected void btnSubmit. lick(object sender, EventArgs e) IbiMessage.Text = "You entered: " + txtName.Text; 3 } where: + Type text into the TextBox and click Submit. + The Label shows what you typed. + ViewState keeps the text in the TextBox even after clicking Submit. 4.5.1 Using the Page Class Every web page in ASP.NET is a custom class that inherits from the System.Web.ULPage control. By inheriting from this class, your page class gains several useful properties. ‘These properties enable functionalities such as caching, validation, and tracing. Some fundamental properties of the page class are given below: > Cache: Stores data for faster access. Page.Cache > IsPostBack: Checks if the page is reloaded. Page.lsPostBack Request: Gets user input and request info. Page Request Response: Sends output to the user. Page.Response Server: Helps manage the server. PageServer > Session: Stores user-specific data. PageSession Trace: Tracks page execution for debugging. Page.Trace User: Provides info about the current user. Page.User ViewState: Saves values between page loads. Page.ViewState Validators: Holds all validation controls. Page.Validators ¥ v o v v . vSending the User to a New Page Hyperlink Control: + What it does: Navigates to another page or external site. + How it works: Renders as an HTML
tag. No server-side events. + Example:
Advertising
Response.Redirect: + What it does: Redirects the user to another page, either on the same server or a differont one. + How it works: Updates the address bar, adds the URL to history, and does not transfer form variables. ‘+ Syntax: Response Redirect("path") Server.Transfer: + What it does: Redirects the user to another page on the same server without changing the URL in the address bar. + How it works: Happens on the server-side, does not update the address bar, and allows transferring query strings and form variables. + Syntax: Server.Transfer("path") 4.5.2 Using Application Events The Global.asax file, also known as the ASP.NET application file, handles application and module level events in one place. It's used for tasks like implementing application security. + Location: Root application directory. + Inclusion: Automatically added to new ASP.NET projects by the .NET IDE, but itis optional and can be deleted if not needed. + File Type: The asax extension shows it’s an application file, not a typical ASP.NET. page. + Security: Direct HTTP requests to this file are automatically rejected, so users can't download or view it. + Updates: Changes to Global.asax automatically reboot the application, closing browser sessions, flushing state info, and restarting the application domain. Event Handling Methods ‘© Application_Start(: Fires when the application starts. ‘* Application_End() Fires when the application ends. + Application_BeginRequest(: Fires at the start of a request. ‘* Application_EndRequest(): Fires at the end of a request. # Session_Start(): Fires when a new session starts ‘* Session_End(): Fires when a session ends. + Application_ErrorQ: Fires on an unhandled error. 4.5.3 Configuring an ASP.NET Application ‘The configuration file manages settings that define a website. These settings are stored in XML files, separate from your application code, allowing independent configuration. + Main File: Typically, a website has a single Web.config file in the application root directory.+ Multiple Files: You can have multiple configuration files for different levels within an application. Important Settings in Configuration Files 1, Authentication and Authorization: Manage user access and permissions. Connection Strings: Store database connection details. App Settings: Store custom application settings. Error Handling: Configure custom error pages. Session State: Manage session settings and state storage. Compilation: Configure settings for how code is compiled, Custom HTTP Handlers and Modules: Define custom processing for HTTP requests. Nae eE Some of the most frequently used configurations, stored conveniently inside Web.config file are: + Database connections + Caching settings + Session States + Error Handling + Security Configuration file looks like this:
Benefits of XML-based Configuration files + ASP.NET Configuration system is extensible and application specific information can be stored and retrieved easily. Its human readable. + You need not restart the web server when the settings are changed in configuration file. ASP.NET automatically dotocte tho changes and applies thom to the running ASP.NET application. + You can use any standard text editor or XML parser to create and edit ASP.NET configuration fies. Different types of Configuration files 1.Machine.config: Server or machine-wide configuration file 2.Web.config: Application configuration files which deal with a single application Ex, Program to display the number of visitors currently browsing your website. Sal * To Create website and adding webform to it please refer point number 4.1. ‘© Adding a Global.asax to web application: ‘Add New Item > Global Application Class > Addoe Global.asax <%@ Application Language="C#" 96> Web.config
"InProc" cookieless="false" timeout="1"/> true" targetFramework="4.5.2" /> P Defaultaspx <%@ Page Language: Inherits="_Defaule” %> rue" Codel "C#" AutoEventWireu Default.aspx. thttp://www.w3.org/1999/xhtml"> verver"> title>
Visitors Count :<%=Application["OnlineUsers").ToString( ) %>
F , wr - ol x 7D) tocathost x \\\ SO locathost:3363/... | O Apps latest hollywood hi » Visitors Count 3 In above example following configuration line is used in web.config fie.
‘+ Timeout: This option controls the length of time a session is considered valid. The session timeout is a sliding value; on each request the timeout period is set to the current time plus the timeout value 5.1 Stepping Up to Web Controls Controls are the building blocks in web form Server controls are tags that are understood by the server. Web server controls are special ASP.NET tags understood by the server. Web server controls are also created on the server and they require a runat="server" attribute to work, Basic Web controls provide the same functionality as their HTML server control counterparts. However, basic Web control include additional methods, events, and properties. 5.2 Web Control Classes Web control classes are the basic control classes used in ASP.NET. Web control classes are defined in the System.Web.ULWebControls namespace. The following diagram shows the web control hierarchy. Web server controls can be divided into following categories: ‘* Validation controls: Validation controls are used to v: work by running client-side script. ‘* Data source controls: Data source controls provides data binding to different data sources. ‘+ Data view controls: Data view controlsare various lists and tables, which can bind to data from data sources for displaying. * Personalization controls: Personalization controls are used for personalization of a page according to the user preferences, based on user information. late user input and they* Login and security controls: Login and security controls provide user authentication, ‘* Master pages: Master page controls provide consistent layout and interface throughout the application. ‘* Navigation controls: Navigation controls help in navigation. Ex. menus, tree view. ‘© Rich controls: Rich controls implement special features. Ex. AdRotator, Calendar control ‘The syntax for creating a Web server control is
Ex. tn" Text="Click Hers
Most web controls hegin by inheriting from the WebControl base class. This class defines the essential functionality for tasks such as data binding and includes some basic properties that you can use with almost any web control. Property Description ‘AccessKey Used to set a key with which a control can be accessed at the client by pressing the associated letter: BackColor Used to change the color of the background ForeColor (BackColor) and text (ForeColor) of the control. BorderColor Used to Change the border of control in the browser. BorderStyle Each of these three ASP.NET properties maps directly BorderWidth to its CSS counterpar It is used to define the HTML class attribute for the a control in the browser. This class name then points to a CSS class you defined in the page or an external CSS hile. Enabled determines whether the user can interact with Enabled the control in the browser. Ex,, with a disabled text box (Enabled="False”) you cannot change its text. — Used to define different font-related settings, such as Font-Size, Font-Names, and Font-Bold. Height It determines the height and width of the control in the Width browser. Sets the clientside HTML tabindex attribute that TabIndex determines the order in which users can move through the controls in the page by pressing the Tab key. Used to set a tooltip for the control in the browser. Itis ToolTip displyed when the user hovers the mouse over the relevant HTML element. Visible It indicates whether a server control is visible or not. UniquelD Unique identifier. ‘SkinID ‘Gets or sets the skin to apply to the controlStyle Gets a collection of text attributes that will be rendered asa style attribute on the outer tag of the Web server control. IsViewStateEnabled | It ins control ites whether view state is enabled for this 5.2.1 Units + Controls like BorderWidth, Height, and Width require a Unit structure combining a numeric value with a unit type (e.g, pixels, percentage). + Example:
5.2.2 Enumerations + Enumerations group related constants for control properties Font, and Color. + Example: Button1.BorderStyle = BorderStyle.Dashed; //C# 5.2.3 Colors + Color property uses the System Drawing namespace. Colors ean be defined by ARGB values, predefined .NET color names, or HTML color names. + Example: Label1.ForeColor = System.Drawing.Color.Red; 5.2.4 Fonts + The Font property references a FontInfo object with properties like Name, Size, and styles (Bold, Italic, ete). + Example: Label Font = new Font(FontFamily.Arial, 12.0F, FontStyle.Bold); //C# 5.2.5 Default Button + The DefaultButton property triggers a specified button when the Enter key is pressed in a form. + Example:
5.3 List Controls ‘These controls are used to display the list with some list item in the page. These controls include ListBox. DropDownList. CheckBoxList, RadioButtonList, and BulletedList. To add items to the list, we have to define
elements between the opening and closing tags of the control. List controls are used to display lists of items on a page. 1. ListBox: Displays a list of tems in a box. Example:
'>TEA (C">COFFEE
MILK 2, DropDownList: Displays a list in a drop-down manner. Example:
TEA
COFFEE
MILK
Common Properties for ListBox and DropDownList: + Items: Collection of ListItem objects. + Rows: Number of items displayed; adds a scrollbar if needed. + Selectedindex: Index of the selected item. + SelectedValue: Value of the selected item, + SelectionMode: Allows single or multiple selections. 3. CheckBoxList: A list of checkboxes arranged horizontally or vertically. Fxample:
TEA
COFFEE
MILKs/asp-Listltem>
4, RadioButtonList: Alist of radio buttons arranged horizontally or vertically. Example;
TEA
COFFEE
Common Properties for CheckBoxList and RadioButtonList: + RepeatLayout: Determines whether to use table tags or normal HTML flow for formatting. + RepeatDirection: Specifies the direction (Horizontal/Vertical) of items. + RepeatCalumne: Number afeolumns when repeating cantrals 5. BulletedList Creates bulleted or numbered lists. Example: asp
"TEA">TEA
‘COFFEE" Selected="True">COFFEE ‘MILK"> Common Properties for BulletedLi + BulletStyle: Defines the type of bullet (e.g, Numbered, Lowerdlpha), + BulletimageUrl: Points to an image used as a bullet if BulletStyle is set to Customimage.+ FirstBulletNumber: Sets the first value in ordered lists. + DisplayMode: Determines if items are rendered as text or hyperlinks. 5.4 Table Controls In the .NET Framework, the Table class allows you to build an HTML table. This class, along with other web controls, is defined in the System.Web.UL.Controls namespace. Below are the main controls associated with building tables and their descriptions: (CONTROL coDE [DESCRIPTION [Represents the main HTML table tag |Table |
which is built using TableRow andl ‘TableCell. [Encapsulates a row within a table, |TableRow |casp:TableRow> Jallowing for setting or getting ro [cell values using TableCell. [TableCell [casp:TableCell> [Encapsulates a cell within a table. (Manages a collection of table rows] including adding or removing rows. |TableRowCollection|
(Manages a collection of table cells] frabiecentcote including adding or removing cells. ion ||
[rableHeaderc [
__|Encapsulates a table header cell Properties of the Table Class + BacklmageUrl: URL to an image used as the background for the table. + Caption: The caption of the table. + CaptionAlign: The alignment of the caption text. + CellPadding: The space between the cell walls and contents. + CellSpacing: The space between cells. + GridLines: The gridline format in the table. = HorizontalAlign: Tho horizontal alignmont of the table on the page. + Rows: A collection of rows in the table. + Runat: Specifies that the control is a server control. Must be set to "server". Ex.
S
T
Y
V
Output: ST YvV 5.5 Web Control Events and AutoPostBack ‘The following diagram shows the order of events in ASP .Net page processing. NNswet_[ ASENET crews aay obec. T seen Web cnt Pa Ponta _ [ASPET crets paar obec ———— ————— In ASP.NET, events on web controls can either trigger an immediate postback or wait until the next postback to process. This is managed through the AutoPostBack feature. Here's how it works: 1. Immediate Event Handliny Some controls, like buttons, post back the page immediately when clicked, triggering events like Click instantly. 2. Delayed Event Handling: Other controls, such as TextBox or DropDownList, have events like TextChanged or SelectedindexChanged that don't trigger a postback automatically. You can either wait until the next postback (e.g,, when another control like a button is clicked) or use AutoPostBack to trigger an immediate postback when these events occur. Event Handling Options + Without AutoPostBack: Events like SelectedindexChanged will only be processed on the next postback, potentially resulting in multiple events firing in an undetermined order. + With AutoPostBack: Setting a control’s AutoPostBack property to true ensures the page is posted back immediately when the user interacts with the control, allowing for immediate processing. Common Events and AutoPostBack BehaviorEvent Web Controls ‘Always Posts Back Click Button, ImageButton True ‘TextChanged TextBox False CheckedChanged CheckBox, RadioButton False ‘SelectedindexChanged | DropDownList, ListBox, CheckBoxList, | False RadioButtonList + AutoPostBack Considerations: While AutoPostBack allows tor immediate event processing, it can make pages less responsive due to the added delay of postback and refresh. Use it selectively based on the desired user experience. Following figure shows the sequence of events in ASP .Net page life cycle. ‘age ablectis created from aspx fle + —_ ro [Fontrolsare repopulate with information from view] a Pageinit vent orcas ge oad event oars se “llother events accu (ike Gand Change eveats) PageraRender event occurs ‘Controlinformaton stored view wate "HIM for page srendeved (and can nolonger be changed) + PasecUnload event oonars a Page bjedis lessed Fommemony 5.5.1 A PostBack occurs when an ASP.NET page is submitted to the server for processing, typically when information needs to be verified or processed on the server side. This is necessary tor actions such as validating user credentials against a database, which cannot be handled on the client side alone. What is AutoPostBack in ASP.NET? AutoPostBack is a property available in many ASP.NET web controls that allows the page to automatically post back to the server Whenever a specific event occurs, such as a change in a DropDownList or TextBox. When AutoPostBack is enabled for a control, the page is immediately submitted to the server, allowing server-side processing of the event.How AutoPostBack Works: When a web page contains controls with AutoPostBack enabled, ASP.NET generates a JavaScript function called doPostBack() in the rendered HI'ML page. This function triggers a Postiack by submitting the form back to the server. Additionally, ASP.NET includes two hidden fields, _EVENTTARGET and —EVENTARGUMENT, which store information about which control triggered the PostBack and any additional event data. Here's an example of how these hidden fields are initially rendered:
"_EVENTARGUMENT” id="_EVENTARGUMENT" valu When the doPostBack() function is called, it sets these fields with the relevant information and submits the form. The function looks like this: ASP.NET automatically generates this function if at least one control on the page uses AutoPostBack. Controls with AutoPostBack enabled are connected to this function using attributes like onclick or onchange, which convert client-side JavaScript events into server-side ASP.NET events. Web Page Life Cycle with AutoPostBack: When a control with AutoPostBack enabled triggers a PostBack, the following sequence of actions occurs: 1. Client-Side Action: The _doPostBack() JavaScript function is invoked, causing the page to be resubmitted to the server. 2. Page Re Creation: ASP.NET re creates the Page object from the .aapx file. 3. State Restoration: ASP.NET retrieves the view state information from the hidden fields and updates the controls on the page accordingly. 4. Page Load: The Page.Load event is triggered 5. Control Event: The specific change event for the control is fired. If multiple contrals trigger events, the arder in which they accur is undetermined 6. PreRender Event: The Page.PreRender event fires, and the page is rendered into an HTML page. 7. Page Unload: The Page.Unload event occurs. 8. Page Response: The newly processed page is sent back to the client, 5.6 Validation Validation is crucial when creating ASP.NET web pages for user input to ensure the data entered is correct and meets the required criteria. ASP.NET provides built-in validation controls that make it easy to validate user input and display error messages if needed. 5.7 Validation Controls: Validation controls in ASP.NET help prevent user input errors, such as entering text where a number is required. ‘These controls validate input when certain events occur, such as pressing a key or clicking another control. Types of Validation Controls:1. RequiredFieldValidator: Ensures that a field is not left empty, 2. RangeValidator: Ensures the input value is within a specified range. CompareValidator: Compares the value in one control with another or with a fixed value. 4, RegularExpressionValidator: Validates input based on a regular expression pattern. 5. CustomValidator: Allows custom validation logic, both client-side and server- side. 6. ValidationSumurary: Displays su rary of all validation errors un the page. ControlToValidate Indicates the input control to validate. ErrorMessage Indicates error string. 1. RequiredFieldValidator Control ‘The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box to force input into the text box. Syntax:
Ex. Your Name :
2. RangeValidator Control ‘The RangeValidator control verifies that the input value falls within a predetermined range. It has three specific properties: Property Description Type Tt defines the type of the data. The available values are: Currency, Date, Double, Integer, and String. MinimumValue | Itspecifies the minimum value of the range. MaximumValue | Itspecifies the maximum value of the range. Syntax:
Not_—_valid age
3. CompareValidator Control ‘The CompareValidator control compares a value in one control with a fixed value or a value in another control. It has the following specific properties: Property Description Type Itspecifies the data type. ControlToCompare | It specifies the value of the input control to compare with ValueToCompare _| It specifies the constant value to compare with. Operator It specifies the comparison operator, the available values are: Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual, and DataTypeCheck Syntax:
Password should match!
server" id="txt11" rextMod Password!" />
ReEnter 4, RegularExpressionValidator ‘The RegularExpresslonValidatur allows validating the Input ext by 1 wching agalast a pattern ofa regular expression. The regular expression is set in the ValidationExpression property. The following table summarizes the commonly used syntax constructs for regular expressions: Syntax: Fx.
Email ID:
Please enter valid email address!
5. CustomValidator ‘The CustomValidator control allows writing application specific custom validation routines for both the client side and the server side validation. The client side validation is accomplished through the ClientValidationFunction property. The client side validation routine should be written in a scripting language, such as JavaScript or VBScript, which the browser can understand. The server side validation routine must be called from the control's ServerValidate event handler. The server side validation routine should be written in any .Net language, like C# or VB.Net Syntax:
server" "CustomValidator"> Ex Custom text:
"txtCustom" /> ‘ustomValidator1" ControlToValidate="txtCustom" "Red" nat="server" Font-Name="Verdana" Font-Size=" ‘oreColor="Red" />
"Validate" — OnClick="ValidateBtn_OnClick" ‘1Opt" 6. ValidationSummary ‘The ValidationSummary control does not perform any validation but shows a summary ofall errors in the page. The summary displays the values of the ErrorMessage property ofall validation controls that failed validation. ‘The following two mutually inclusive properties list out the error message: ShowSummary: shows the error messages in specified format. ShowMessageBua. slivws the eur weonayes itt a separate wisnluw, ‘Ex. asp:ValidationSummary ID="ValidationSummary1" runat="server" Style="top: 390px; left: 44px; position: absolute; height: 38px; width: 625px" /> Validation Groups Complex pages have different groups of information provided in different panels. In such situation, a need mightarise for performing validation separately for separate group. This kind of situation is handled using validation groups. To createa validation group, you should put the input controls and the validation controls into the same logical group by setting their ValidationGroup property. Ex.
"sy">
5.8 Rich Controls ASP Net page framework pravides a few, task-specific cantrols called rich controls. Rich controls are built with multiple HTML elements and contain rich functionality. Examples ofrich controls are the Calendar control and the AdRotator control. 5.8.1 Calendar Control + The Calendar control displays a one-month calendar in the browser, allowing users to select dates and navigate between months. + Key Features: © Select a single day, a week, ora range of days. © Navigate between mot © Customize the display of days, weekends, and today's date. Calendar ID= + Propertise * SelectedDate: Sets/gets the selected date * VisibleDate: Sets/zets the displayed month. * ShowNextPrevMonth: Shows/hides month navigation buttons ‘alendar1" runat=' "server"> FirstDayOfWeek: Sets the first day of the week. SelectionMode: Defines what can be selected (day, week, month). + Events: © SelectionChanged: Triggered when a date is selected. o DayRender: Triggered when a day cell is rendered. © VieibleMonthChanged: Triggered when the visible month changes. 5.8.2 AdRotator Control + The AdRotator control displays images randomly from a list, often used for rotating banner ads. + Advertisement File: Stores image details in an XML format, specifying the image URL, navigation URL, alternate text, keyword, and impression count. Example XML: xml
prosetech.jpg
-
http://www.prosetech.com
ProseTech Site
-
1
Computer
+ Properties:-blank: Opens the link ina new window. _parent: Opens the linkin the parent frame. © self: Opens the link in the current frame. -top: Opens the link in the topmost frame. 5.8.3 Pages with Multiple Views The MultiView and View controls divide the content of a page into different groups, displaying only one group ata time. Each View control manages one group of content and all the View controls are held together in a MultiView control. ‘The MultiView control is responsible for displaying one View control at a time. The View displayed is called the active view. Syntax of MultiView: ~
"server"> Syntax of View:
However, the View control cannot exist on its own. It would render error if you try to use itstand-alone. It is always used with a Multiview control as:
-w Control: + Visible: Boolean property that sets the visibility of the view. MultiView Control: «Views: Collection af View controls within the MultiView, + ActiveViewIndex: Index of the active view; -1 if no view is active. CommandName Attributes (for navigation): + NextViewCommandName: "NextView" - Navigates to the next view. + PreviousViewCommandName: "PrevView" - Navigates to the previous view. + SwitchViewByIDCommandName: "SwitchViewByID" - Switches view by ID. + SwitchViewByIndexCommandName: "SwitchViewByIndex" - Switches view by index. Important Methods: ‘+ SetActiveView: Sets the active view.+ GetActiveView: Retrieves the active view. Important Events: + ActiveViewChanged: Triggered when a view is changed. + Activa ‘riggered by the active view. + Deactivate: Triggered by the inactive view. User controls User controls are reusable components derived from the System.Web.UI.UserControl class. Characteristics: + File Extension: ascx : Cannot contain , , or
tags. + Directive: Uses Control directive instead of Page. ‘To create and use the user control, take the following steps: + Create a new web application, + Website -> Add -> Web User Control and Name it ‘footer’ Bit serecten El tet footerascx <%@ Control Language="C#" AutoEventWireup="true" CodeFil Inherits="footer" %>
‘
choad runat—"sorver"~ title>
“form.” runat OUTPUT: “= - a x Deamon x € > ¢ [O becahose * 0 eee tte halon 7 ‘Welcome to ASPNet In above application (2) The Register directive specifies 4 lay namie a> well a> lay prefia for Une control, <%@ Register Src="~ /footer.ascx" TagName="footer” TagPrefix="Tfooter” %> (2) The following tag name and prefix should be used while adding the user control on the page:
5.9.2 Dynamic Graphics Graphics Device Interface resides in System.Drawing.dll assembly. All graphics classes are reside in the System.Drawing, System.Text, System.Printing, System.Internal, System.Imaging, System.Drawing2D and System.Design namespaces. The Graphics Class‘The Graphics class encapsulates Graphics Device Interface drawing surfaces. Before drawing any object (for example circle, or rectangle) we have to create a surface using Graphics class. Graphics Device Interface (GDI): Assembly: System.Drawingdll Namespaces: SystemDrawing, System-Text, System.Printing, System.Internal, System. Imaging, System.Drawing2D, System.Design Graphics Class: Encapsulates drawing surfaces. Methods include: DrawAre: Draws an are. DrawBezier /DrawBeziers: Draws cubic Bezier curves. DrawClosedCurve: Draws closed curve. DrawCurve: Draws a curve. DrawEllipse: Draws an ellipse. Drawlmage: Draws an image. DrawLine: Draws a line. DrawPath: Draws lines and curves defined by a path, DrawPie: Draws a pie section outline. DrawPolygon: Draws a polygon outline. DrawRectangle: Draws a rectangle outline. Drawstring: Draws text. FillENipse/FillPath/FillPic/FillPolygon/FillRectangle/FillRectangles/FillRe gion: Fills shapes with colors or patterns. Graphics Objects: Brush: Fills surfaces with patterns, colors, or bitmaps, Pen: Draws lines and shapes. Font: Describes text rendering font. Color: Describes color used in rendering Ex.1 Drawing ellipse on bitmap Using aspxes file. Defaultaspx.cs using System Drawing Drawing2D; using System. Drawing; using System. Drawing.Imaging; public partial class Default : System.Web.ULPage {protected void Page_Load (object sender, EventArgs e) { Bitmap oCanvas = new Bitmap(200, 150); Graphics g = Graphics FromImage(oCanvas); gClear(Color.White); gDrawEllipse(Pens.Red, 10, 10, 150, 100); // Now, we only need to send it // to the client Response.CuntentType = “image/jpeg; Canvas Save(Response. OutputStream, ImageFormat peg); Response.End( ); // Cleanup gDispose( ); oCanvas.Dispose( ); } } Output: © [0 tocatose #0 5.9.3 The Chart Control + Purpose: Creates various chart images with formatting options and labels. + Chart Types: Includes area, bar, column, line, pie charts, and specialized charts like stock charts. You can switch chart types easily. Data Source: «Use Visual Studio to connect to a database, or provide data froma file or collection. Series and DataPoints. + Series: Contains all data series in the chart, each with: ChartType: Defines the type of chart. ChartArea: Specifies the area where the series is plotted © Legend: Optional legend for the series. © XAxisType/YAxisType: Defines the X and Y axes. + DataPoints: Conta © XValue: X-axis value o YWalues: Y-axis values. Chart Methods:‘+ new Chart: Creates a new chart object with set dimensions. + AddTitleQ): Adds a title to the chart. + AddSeries(): Adds data to the chart, defining chart type, x-values, and y-values. + Write(): Displays the chart Add chart from Toolbox -> Data to website. rassomese 5.10 Website Navigation In ASP.NET, managing changes to the location of pages or resources can lead to problems with internal links. To address this, ASP.NET provides features and controls that significantly enhance site navigation, one of which is the sitemap. A sitemap is essentially asstructured list of all accessible pages on a website, arranged hierarchically. It serves as a comprehensive overview of the site's structure, making it easier for visitors to navigate and for search engine bots to find and index pages. By using sitemaps, you can improve bull user experience aud seared We uplinizati Questions 1. What is the difference between List Box and Drop-Down Lists? List and explain any three common properties of these controls. Write a note on web config Explain AdRotator control with example in ASP.NET Write a note on Global asax fle List and explain any four types of validation controls used in ASP.NET Explain Calendar control with example in ASP.NET Short note on Page class Explain SiteMapPath control in ASP.NET List and explain any 5 templates to create ASP.NET applications. 10, Explain Anatomy of a Webform. 11. Explain any five properties of ListBox and DropDownList controls. 12. Brief about Graphics class and it’s any 5 methods. 13, Write a note on page class 14. Explain view state with an example. eer awawND
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
Rating: 4 out of 5 stars
4/5 (5867)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brené Brown
Rating: 4 out of 5 stars
4/5 (1094)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
Rating: 4.5 out of 5 stars
4.5/5 (866)
Magazines
Podcasts
Sheet music
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
Rating: 4 out of 5 stars
4/5 (614)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
Rating: 4.5 out of 5 stars
4.5/5 (1723)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
Rating: 4 out of 5 stars
4/5 (1200)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
Rating: 4 out of 5 stars
4/5 (597)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
Rating: 4 out of 5 stars
4/5 (909)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
Rating: 4.5 out of 5 stars
4.5/5 (543)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
Rating: 4.5 out of 5 stars
4.5/5 (2109)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
Rating: 4.5 out of 5 stars
4.5/5 (352)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
Rating: 4.5 out of 5 stars
4.5/5 (474)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
Rating: 4 out of 5 stars
4/5 (1039)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
Rating: 4 out of 5 stars
4/5 (824)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
Rating: 4 out of 5 stars
4/5 (1887)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
Rating: 4.5 out of 5 stars
4.5/5 (272)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
Rating: 4.5 out of 5 stars
4.5/5 (122)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
Rating: 3.5 out of 5 stars
3.5/5 (1954)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
Rating: 3.5 out of 5 stars
3.5/5 (411)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
Rating: 4.5 out of 5 stars
4.5/5 (443)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
Rating: 4.5 out of 5 stars
4.5/5 (4834)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
Rating: 4 out of 5 stars
4/5 (98)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
Rating: 4.5 out of 5 stars
4.5/5 (810)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
Rating: 3.5 out of 5 stars
3.5/5 (2268)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
Rating: 4 out of 5 stars
4/5 (4226)
Yes Please
From Everand
Yes Please
Amy Poehler
Rating: 4 out of 5 stars
4/5 (1914)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
Rating: 4.5 out of 5 stars
4.5/5 (268)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
Rating: 4.5 out of 5 stars
4.5/5 (1930)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
Rating: 4.5 out of 5 stars
4.5/5 (235)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
Rating: 3.5 out of 5 stars
3.5/5 (232)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
Rating: 3.5 out of 5 stars
3.5/5 (2552)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
Rating: 4 out of 5 stars
4/5 (3997)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
Rating: 3.5 out of 5 stars
3.5/5 (801)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
Rating: 4 out of 5 stars
4/5 (74)
John Adams
From Everand
John Adams
David McCullough
Rating: 4.5 out of 5 stars
4.5/5 (2410)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M.L. Stedman
Rating: 4.5 out of 5 stars
4.5/5 (789)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
Rating: 3.5 out of 5 stars
3.5/5 (880)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
Rating: 3.5 out of 5 stars
3.5/5 (104)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
Rating: 3.5 out of 5 stars
3.5/5 (137)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
Rating: 4 out of 5 stars
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
Rating: 4 out of 5 stars
4/5 (105)
Unit I Chapter 2
Document
41 pages
Unit I Chapter 2
krpal204
No ratings yet
Unit 1 Chapter 3
Document
22 pages
Unit 1 Chapter 3
krpal204
No ratings yet
U 1 Awp
Document
27 pages
U 1 Awp
krpal204
No ratings yet
u1IOT (Chap1) 22 Jul 24 08 29 06
Document
12 pages
u1IOT (Chap1) 22 Jul 24 08 29 06
krpal204
No ratings yet