Java elements
Java elements
1. Page Request- This is when the page is first requested from the server. When the page is requested,
the server checks if it is requested for the first time. If so, then it needs to compile the page, parse the
response and send it across to the user. If it is not the first time the page is requested, the cache is
checked to see if the page output exists. If so, that response is sent to the user.
2. Page Start – During this time, 2 objects, known as the Request and Response object are created. The
Request object is used to hold all the information which was sent when the page was requested. The
Response object is used to hold the information which is sent back to the user.
3. Page Initialization – During this time, all the controls on a web page is initialized. So if you have any
label, textbox or any other controls on the web form, they are all initialized.
4. Page Load – This is when the page is actually loaded with all the default values. So if a textbox is
supposed to have a default value, that value is loaded during the page load time.
5. Validation – Sometimes there can be some validation set on the form. For example, there can be a
validation which says that a list box should have a certain set of values. If the condition is false, then
6. Postback event handling – This event is triggered if the same page is being loaded again. This
happens in response to an earlier event. Sometimes there can be a situation that a user clicks on a
submit button on the page. In this case, the same page is displayed again. In such a case, the
7. Page Rendering – This happens just before all the response information is sent to the user. All the
information on the form is saved, and the result is sent to the user as a complete web page.
8. Unload – Once the page output is sent to the user, there is no need to keep the ASP.net web form
objects in memory. So the unloading process involves removing all unwanted objects from memory.
Q6) Explain HTML form Elements:-
HTML (HyperText Markup Language) is the standard markup language used to create and design web pages and
webapplications. It provides the basic structure of web content, allowing developers to format text, images, links,
forms, andother elements that are displayed in web browsers.
HTML form elements are used to create interactive forms that allow users to enter and submit data. Beloware the
various HTML form elements, categorized by their function:
Unit 2
Q2)
Q3) what are the validation controls in asp.net explain any two validation control 4m
Q5) Explain Navigation controls
Unit 3
3. Cookies
⮚ Cookie is a small text file which is created by the client's browser and
users.
⮚ Whenever a user makes a request for a page the first time, the server
creates a cookie and sends it to the client along with the requested page
and the client browser receives that cookie and stores it on the client
Types of Cookies:
1. Persistence Cookie:
⮚ Cookies which you can set an expiry date time are called
persistence cookies. ⮚
you set.
2.
Non-Persistence Cookie:
same browser.
1. Hidden field
These examples
1) Client Side:
1. Hidden field
Hidden fields are used to store value to client side.
Hidden field is a control provided by ASP.NET which is used to store small amounts of data
on the client.
Hidden field is not displayed on the browser, but it works on a request.
Let us see with a simple example how to use a hidden field. These examples increase a value by 1 on
every "No Action Button" click.
<asp:HiddenField ID="HiddenField1" runat="server" />
}
protected void Button1_Click(object sender, EventArgs e)
{
//this is No Action Button Click
}
2. View state
Viewstate is a very useful client side property.
View state is another client side state management mechanism provided by ASP.NET to store
user's data
It is used for page level state management.
Viewstate stores any type of data and used for sending and receiving information,
View State provides page level state management i.e., as long as the user is on the current
page, state is available and the user redirects to the next page and the current page state is
lost.
View state is enabled by default for all server side controls of ASP.NET with a property
EnableviewState set to true.
Let us see how ViewState is used with the help of the following example. In the example we
try to save the number of postbacks on button click.
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text=ViewState["count"].ToString();
}
3. Cookies
Cookie is a small text file which is created by the client's browser and also stored on the client hard
disk by the browser.
It does not use server memory. Generally a cookie is used to identify users.
Whenever a user makes a request for a page the first time, the server creates a cookie and sends it to the
client along with the requested page and the client browser receives that cookie and stores it on the client
machine either permanently or temporarily (persistent or non persistence).
Types of Cookies:
1. Persistence Cookie:
Cookies which you can set an expiry date time are called persistence cookies.
Persistence cookies are permanently stored till the time you set.
2. Non-Persistence Cookie:
Non persistence cookies are not permanently stored on the user client hard disk folder.
It maintains user information as long as the user accesses the same browser.
When user closes the browser the cookie will be discarded. Non Persistence cookies are
to read a cookie:
4. Control State
Control State is another client side state management technique.
Whenever we develop a custom control and want to preserve some information, we can use view state
but suppose view state is disabled explicitly by the user, the control will not work as expected.
For expected results for the control we have to use Control State property. Control state is separate from
view state.
e.g.
if (!IsPostBack)
{
lblmsg1.Text = "Welcome to C# corner";
lblmsg2.Text = "Welcome to C# corner community";
}
2) Server Side:
1. Session:-
Session management is a very strong technique to maintain state.
Generally session is used to store user's information and/or uniquely identify a user (or say
browser).
The server maintains the state of user information by using a session ID.
When users makes a request without a session ID, ASP.NET creates a session ID and sends it
with every request and response to the same user.
Session["Count"] = Convert.ToInt32(Session["Count"]) + 1;
//Set Value to The Session
To manage a session, ASP.NET provides two events: session_start and session_end that is written in
a special file called Global.aspx in the root directory of the project.
i) Session_Start: The Session_start event is raised every time a new user makes a request without
a session ID, i.e., new browser accesses the application, then a session_start event raised. Let's
see the Global.asax file.
void Session_Start(object sender, EventArgs e)
{
Session["Count"] = 0; // Code that runs when a new session is started
}
ii) Session_End: The Session_End event is raised when session ends either because of a time
out expiry or explicitly by using Session.Abandon().
void Session_End(object sender, EventArgs e)
{
Response.Write("Session_End");
}
2. Application
Application state is a server side state management technique.
The data stored in application state is common for all users of that particular ASP.NET
application and can be accessed anywhere in the application.
It is also called application level state management. Data stored in the
application should be of small size.
i) Application_start: The Application_Start event is raised when an app domain starts. When the
first request is raised to an application then the Application_Start event is raised.
Let's see the Global.asax file.
Void Application_Start(object sender, EventArgs e)
{
Application["AppstartMessage"] = "Welcome to CSharp";
}
ii) Application_Error: It is raised when an unhandled exception occurs, and we can manage
the exception in this event.
void Application_Error(object sender, EventArgs e)
{
// Write an unhandled error code exception
}
iii) Application_End: The Application_End event is raised just before an application domain ends
because of any reason, may IIS server restarting or making some changes in an application
cycle.
Void Application_End(object sender, EventArgs e)
{
Application["AppEndMessage"] = "Application Closed";
}
Response.Write()
In ASP.NET, Response.Write is a method of the HttpResponse class that allows developers to send raw text or
content directly to the HTTP response stream. This content is then rendered in the user's browser as
part of the webpage. It is commonly used to output strings, HTML, or dynamic content during page
processing.
1. Direct Output: It directly writes the content to the response output stream.
2. Dynamic Content: Useful for injecting text, variables, or HTML content dynamically during
runtime.
3. Basic Debugging: Can be used to inspect variable values or debug logic flow by writing
output to the page.
Example Usage
Response.Write("Hello, World!");
2. Writing HTML
protected void Page_Load(object sender, EventArgs e)
Response.Write("<h1>Welcome to My Website</h1>");
}
This will render an HTML <h1> heading with the text "Welcome to My Website."
}This will render the text Hello, John! inside a paragraph <p>.
Unit 4
Q)Explain Ado.net architecture
The architecture followed by Ado.net for the connectivity with the database is
categorized into two modes:-
The architecture followed by Ado.net for the connectivity with the database is
categorized into two modes:-
Connection: Establishes a link between the application and the database (e.g., SqlConnection
for SQL Server).
Command: Executes SQL commands or stored procedures (e.g., SqlCommand).
DataReader: Provides a way to read a forward-only stream of data rows from a SQL Server
database (SqlDataReader).
1. Connected Architecture
DataReader in Connected architecture
In order to make an object of the DataReader class, we never use the new keyword instead we call
the ExecuteReader() of the command object. For e.g.
SqlDatareader rdr=cmd.ExecuteReader(cmd);
Here cmd.ExecuteReader() executes the command and creates the instance of DataReader class and
loads the instance with data. Therefore, we do not use the ‘new’ keyword.
2. Disconnected Architecture
Disconnected Architecture in ADO.NET
On the other hand, the disconnected architecture allows the application to interact with the database
without maintaining a constant connection. Data is retrieved from the database and stored in an in-
memory representation. Any changes made to this in-memory data can later be reconciled with the
database.
Empl;
In the above lines of code, the object of the SqlDataAdapter is responsible for establishing the
connection. It takes query and ConnectionString as a parameter. The query is issued on the
database to fetch the data. ConnectionString allows connectivity with the database. The fill() of the
SqlDataAdapter class adds the Table.
Q)Explain data Adapter and data Set.
DataAdapter
DataAdapter will acts as a Bridge between DataSet and database. This dataadapter
object is used to read the data from database and bind that data to dataset.
Dataadapter is a disconnected oriented architecture. Check below sample code to
see how to use DataAdapter in code:
protected void BindGridview() {
SqlConnection con = new SqlConnection("Data Source=abc;Integrated
Security=true;Initial Catalog=Test");
conn.Open();
DataSet