1) What is view state?
=> When a form is submitted in classic ASP, all form values are
cleared. Suppose you have submitted a form with a lot of information and the
server comes back with an error. You will have to go back to the form and
correct the information. You click the back button, and what happens.......ALL
form values are CLEARED, and you will have to start all over again! means The site
did not maintain your ViewState.
=> When a form is submitted in ASP .NET, the form reappears in the
browser window together with all form values. How come? This is because ASP
.NET maintains your ViewState.
=> The ViewState indicates the status of the page
when submitted to the server. The status is defined through a hidden field
placed on each page with a <form runat="server"> control.
2) Where these view state will be saved?
=> Viewstate is stored
on page it self in encoded form. You can't access the viewstate in client
side in a direct manner. You need to know the encoding/decoding algorithms to
fetch the valuable data from this viewstate in clientside code.
=> You can use hidden
variable to store data that will be used only on that page. Hidden variables
are accessible from client side and server side code.
=> You can use Cache
or session to store datatable (large data). They will have good performance
as compare to ViewState.
=> The Cache is always
using the machine's memory, the Session uses what has been configured:
=> In a web farm the
Session can be local (which works only if affinity is set), or remote (state
server or database, or custom), but the cache is always local.
=> So, storing a
DataTable in the cache will consume memory, but it will not use
serialization.
PS: storing a DataSet
instead of a DataTable will change almost nothing.
3) Disadvantages
of view state.
These are the main disadvantages of using View
State:
1. It can be performance overhead if we are going to
store larger amount of data , because it is associated with page only.
2. Its stored in a hidden filed in hashed format still
it can be easily trapped.
3. It does not have any support on mobile devices.
4) If there is a login page and a user gives his
credentials, u have to authenticate it and display the user name in all other
pages? How will u do it? What concept will u use for it?
for the current structure of your project, you can
create a Session variable on the login page after verifying the user
credentials and store logged in user details i.e.
in your login page, login button click handler do
this:
protectedvoidbtnLogin_Click(object sender, EventArgs e)
{
string username= txtUsername.Text;
string pwd = txtPassword.Text;
//call your logic to verify user credentials.
VerifyUserCredentialFromDb(username, pwd);
if(UserValid)
{
Session["User"] =
GetUserObject(username,pwd);
//whatever your logic is, make sure, you create the Session
object, before
//below line,whereever you are doing it
Response.Redirect("Home.aspx");
}
}
and in the Page_load of all the other
pages
protectedvoidPage_Load(object
sender, EventArgs e)
{
if(Session["User"]==null)
Response.Redirect("login.aspx");
}
|
5)
What are cookies?
=> A cookie is a small bit of text that accompanies
requests and pages as they go between the Web server and browser. The cookie
contains information the Web application can read whenever the user visits the
site.
=> Cookies provide a means in Web applications to
store user-specific information. For example, when a user visits your site, you
can use cookies to store user preferences or other information. When the user
visits your Web site another time, the application can retrieve the information
it stored earlier.
6)
How to access the values globally throughout the
application in .NET?
Session Variables Session
variables are stored in the server's memory for each user, and can be read and
written to as often as required. These are limited to a per-user basis, so if
you want to hold a single variable for all users, then this isn't the way to
go.
Usage:
Session["MyVariable"]
= 5;
intmyVariable = (int)Session["MyVariable"]; //Don't
forget to check for null references
7)
Various modes of storing ASP.net session
ASP.NET session state supports several different
storage options for session data. Each option is identified by a value in the SessionStateMode enumeration.
The following list describes the available session state modes:
9)
Explain about Partial classes?
There
are several situations when splitting a class definition is desirable:
C#
public partial class
Employee
{
public voidDoWork()
{
}
}
public partial class
Employee
{
public voidGoToLunch()
{
}
}
The
partial keyword indicates that other parts of the class, struct, or interface
can be defined in the namespace. All the parts must use the partial keyword.
All the parts must be available at compile time to form the final type. All the
parts must have the same accessibility, such as public, private, and so on.
10)
Difference between Dataset.clone and dataset.copy?
Clone :- copies only the structure of the dataset.
it includes all datatable schemas their constraints and exlcuding data in those
datatables.
DataSet dswithData;//this is containing datatable schamas
DataSet dsNew;
dsNew=dswithData.Clone();
while Copy() : methods copies all the dataset including its datatables schemas, constraints along with the data.
<prelang="cs">
DataSetdswithData;//this is containing
datatableschamas
DataSetdsNew;
dsNew=dswithData.Copy();
</pre>
|
Hi Dinesh Kumar how r u? this is Vivekanandan did you remember me we just meet together in Bank of America interview. And your blogspot is very useful for me you done a very great job.Keep in touch bye..,
ReplyDelete