0% found this document useful (0 votes)
3 views21 pages

Java elements

The document outlines key concepts in web development, focusing on ASP.NET, including the differences between web browsers and servers, the ASP.NET page lifecycle, HTML form elements, validation controls, and state management techniques. It also discusses cookies, hidden fields, and the ADO.NET architecture, detailing connected and disconnected modes of database interaction. Furthermore, it explains the use of Response.Write for outputting content in ASP.NET applications.

Uploaded by

evilangele777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views21 pages

Java elements

The document outlines key concepts in web development, focusing on ASP.NET, including the differences between web browsers and servers, the ASP.NET page lifecycle, HTML form elements, validation controls, and state management techniques. It also discusses cookies, hidden fields, and the ADO.NET architecture, detailing connected and disconnected modes of database interaction. Furthermore, it explains the use of Response.Write for outputting content in ASP.NET applications.

Uploaded by

evilangele777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

UNIT 1

Q1) Difference between Web Browser and Web Server.


Q3) difference Between GET and POST

Q4) Explain ASP.Net Page Lifecycle 4 marks


ASP.Net Page Lifecycle

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

there should be an error in loading the page.

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

Postback event handler is called.

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

Q)diffrenece between Reponse redirect and serve Transfer.

Q)Short note on Cookies.

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.

⮚ A cookie is a small file that stores user information.

⮚ 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.

Let us see how to create persistence cookies.

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 useful for public computers.

Let us see how to create non persistence cookies.

Q)Short note on Hidden Field Control.

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

In the code-behind page:


Q) Explain client side state management.

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" />

In the code-behind page:

protected void Page_Load(object sender, EventArgs e)


{
if (HiddenField1.Value != null)
{
int val= Convert.ToInt32(HiddenField1.Value) + 1; HiddenField1.Value = val.ToString();
Label1.Text = val.ToString();
}

}
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 Page_Load(object sender, EventArgs e)


{
if (IsPostBack)
{
if (ViewState["count"] != null)
{
int ViewstateVal = Convert.ToInt32(ViewState["count"]) + 1; Label1.Text =
ViewstateVal.ToString(); ViewState["count"]=ViewstateVal.ToString();
}
else
{
ViewState["count"] = "1";
}
}

}
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.

A cookie is a small file that stores user information.

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.

Let us see how to create persistence cookies.

Response.Cookies["nameWithPCookies"].Value = "This is A Persistance Cookie";


Response.Cookies["nameWithPCookies"].Expires =
DateTime.Now.AddSeconds(10);

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

useful for public computers.

Let us see how to create non persistence cookies.

Response.Cookies["nameWithNPCookies"].Value = "This is A Non Persistance Cookie"; How

to read a cookie:

if (Request.Cookies["NonPersistance"] != null) Label2.Text =


Request.Cookies["NonPersistance"].Value;

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";
}

Q) Explain Server side state managemet.

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.

How to get and set value in Session:

Session["Count"] = Convert.ToInt32(Session["Count"]) + 1;
//Set Value to The Session

Label2.Text = Session["Count"].ToString(); //Get Value from the Sesion

Session Events in ASP.NET

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.

How to get and set a value in the application object:

Application["Count"] = Convert.ToInt32(Application["Count"]) + 1; //Set Value to The Application


Object

Label1.Text = Application["Count"].ToString(); //Get Value from the Application Object

Application events in ASP.NET


There are three types of events in ASP.NET. Application event is written in a special file called
Global.asax.

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";
}

Q) Explain Response Write

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.

Key Features of Response.Write

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

1. Writing Plain Text


protected void Page_Load(object sender, EventArgs e)

Response.Write("Hello, World!");

This will display Hello, World! as plain text in the browser.

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."

3. Writing Dynamic Content


protected void Page_Load(object sender, EventArgs e){
string name = "John"; Response.Write($"<p>Hello,
{name}!</p>");

}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:-

Ado.net is both connection-oriented as well as disconnection

Types of Architecture oriented. Depending upon the functionality of an application, we can


make it connection-oriented or disconnection oriented. We can even use both the modes together
in a single application.

Connected Architecture in ADO.NET


In the connected architecture, an application interacts directly with the database using a connection.
This means that the connection remains open as long as the application needs to interact with the
database, and it’s closed when the operations are completed. The connected architecture is primarily
used for direct, real-time access to the database.

Components of Connected Architecture in ADP.NET:

 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.

SqlCommand cmd= new SqlCommand(“Select * from Table”);

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.

Components of Disconnected Architecture in ADP.NET:

 DataSet: An in-memory Data set consisting of one or more DataTable objects.


 DataAdapter: Acts as a bridge between the DataSet and the data source for retrieving
and saving data. It executes SQL commands and stores the results in the DataSet. 
 Connection: Used for brief periods to fetch data or update the database.
DataAdapter in Disconnected architecture
For example:-

public DataTable GetTable(string query)

SqlDataAdapter adapter = new SqlDataAdapter(query, ConnectionString);


adapter.Fill(Empl); return

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();

SqlCommand cmd = new SqlCommand("Select UserName, First


Name,LastName,Location FROM Users", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds =
new DataSet();
sda.Fill(ds);

gvUserInfo.DataSource = ds; gvUserInfo.DataBind();

DataSet

DataSet is a disconnected orient architecture that means there is no need of active


connections during work with datasets and it is a collection of DataTables and relations
between tables. It is used to hold multiple tables with data. You can select data form
tables, create views based on table and ask child rows over relations. Also DataSet provides
you with rich features like saving data as XML and loading XML data.
protected void BindGridview() {
SqlConnection conn = new SqlConnection("Data Source=abc;Integrated
Security=true;Initial Catalog=Test");
conn.Open();

SqlCommand cmd = new SqlCommand("Select UserName, First


Name,LastName,Location FROM Users", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd); DataSet ds =
new DataSet();
sda.Fill(ds);
gvUserInfo.DataSource = ds;
gvUserInfo.DataBind();

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy