ASP.NET Interview Questions
Ques: 1 What does the keyword virtual declare for a method?
Ans:The method or property can be overridden.
Ques: 2 Tell me implicit name of the parameter that gets passed into the set property
of a class?
Ans:The data type of the value parameter is defined by whatever data type the property is declared as.
Ques: 3 What is the difference between an interface and abstract class ?
Ans:1. In an interface class, all methods are abstract and there is no implementation. In an abstract class some methods can be concrete.
2. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.
Ques: 4 How to Specify the accessibility modifier for methods inside the interface?
Ans:They all must be public, and are therefore public by default.
Ques: 5 Define interface class ?
Ans:Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.
Ques: 6 When you declared a class as abstract?
Ans:1. When at least one of the methods in the class is abstract.
2. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
Ques: 7 Define abstract class?
Ans:1. A class that cannot be instantiated.
2. An abstract class is a class that must be inherited and have the methods overridden.
3. An abstract class is essentially a blueprint for a class without any implementation
Ques: 8 How to allowed a class to be inherited, but it must be prevent the method from being over-ridden?
Ans:Just leave the class public and make the method sealed.
Ques: 9 How to prevent your class from being inherited by another class?
Ans:We use the sealed keyword to prevent the class from being inherited.
Ques: 10 What class is underneath the SortedList class?
Ans:A sorted HashTable.
Ques: 11 What is the .NET collection class that allows an element to be accessed using a unique key?
Ans:HashTable.
Ques: 12 Difference between the System.Array.Clone() and System.Array.CopyTo()?
Ans:The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element’s object, resulting in a different, yet identacle object.
Ques: 13 Difference between System.String and System.Text.StringBuilder classes?
Ans:
System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
Ques: 14 What is the top .NET class that everything is derived from?
Ans:System.Object.
Ques: 15 How can you automatically generate interface for the remotable object in .NET?
Ans:Use the Soapsuds tool.
Ques: 16 How to configure a .NET Remoting object via XML file?
Ans:It can be done via machine.config and application level .config file (or web.config in ASP.NET). Application-level XML settings take precedence over machine.config.
Ques: 17 What is Singleton activation mode?
Ans:A single object is instantiated regardless of the number of clients accessing it. Lifetime of this object is determined by lifetime lease.
Ques: 18 What security measures exist for .NET Remoting?
Ans:
None.
Ques: 19 In .NET Remoting, What are channels?
Ans:Channels represent the objects that transfer the other serialized objects from one application domain to another and from one computer to another, as well as one process to another on the same box. A channel must exist before an object can be transferred.
Ques: 20 What are remotable objects in .NET Remoting?
Ans:1. They can be marshaled across the application domains.
2. You can marshal by value, where a deep copy of the object is created and then passed to the receiver. You can also marshal by reference, where just a reference to an existing object is passed.
Ques: 21 Do you know the proxy of the server object in .NET Remoting?
Ans:This process is known as marshaling. It handles the communication between real server object and the client object. We can say that It’s a fake copy of the server object that resides on the client side and behaves as if it was the server.
Ques: 22 Give your idea when deciding to use .NET Remoting or ASP.NET Web Services?
Ans:1. Remoting is a more efficient communication exchange when you can control both ends of the application involved in the communication process. 2. Web Services provide an open-protocol-based exchange of informaion. Web Services are best when you need to communicate with an external organization or another (non-.NET) technology.
Ques: 23 Define the possible implementations of distributed applications in .NET?
Ans:.NET Remoting and ASP.NET Web Services. If we talk about the Framework Class Library, noteworthy classes are in System.Runtime.Remoting and System.Web.Services.
Ques: 24 Explain what relationship is between a Process, Application Domain, and Application?
Ans:A process is an instance of a running application. An application is an executable on the hard drive or network. There can be numerous processes launched of the same application (5 copies of Word running), but 1 process can run just 1 application.
Ques: 25 What’s typical about a Windows process in regards to memory allocation?
Ans:Each process is allocated its own block of available RAM space, no process can access another process’ code or data. If the process crashes, it dies alone without taking the entire OS or a bunch of other applications down.
Ques: 26 What’s a Windows process?
Ans:It’s an application that’s running and had been allocated memory.
Ques: 27 Using XSLT, how would you extract a specific attribute from an element in an XML document?
Ans:Successful candidates should recognize this as one of the most basic applications of XSLT. If they are not able to construct a reply similar to the example below, they should at least be able to identify the components necessary for this operation: xsl:template to match the appropriate XML element, xsl:value-of to select the attribute value, and the optional xsl:apply-templates to continue processing the document.
Ques: 28 What is SOAP and how does it relate to XML?
Ans:The Simple Object Access Protocol (SOAP) uses XML to define a protocol for the exchange of information in distributed computing environments. SOAP consists of three components: an envelope, a set of encoding rules, and a convention for representing remote procedure calls. Unless experience with SOAP is a direct requirement for the open position, knowing the specifics of the protocol, or how it can be used in conjunction with HTTP, is not as important as identifying it as a natural application of XML.
Ques: 29 What is main difference between Global.asax and Web.Config?
Ans:ASP.NET uses the global.asax to establish any global objects that your Web application uses. The .asax extension denotes an application file rather than .aspx for a page file. Each ASP.NET application can contain at most one global.asax file. The file is compiled on the first page hit to your Web application. ASP.NET is also configured so that any attempts to browse to the global.asax page directly are rejected. However, you can specify application-wide settings in the web.config file. The web.config is an XML-formatted text file that resides in the Web site’s root directory. Through Web.config you can specify settings like custom 404 error pages, authentication and authorization settings for the Web site, compilation options for the ASP.NET Web pages, if tracing should be enabled, etc
Ques: 30 What is the difference between the value-type variables and reference-type variables in terms of garbage collection?
Ans:The value-type variables are not garbage-collected, they just fall off the stack when they fall out of scope, the reference-type objects are picked up by GC when their references go null.
Ques: 31 Where do the reference-type variables go in the RAM?
Ans:The references go on the stack, while the objects themselves go on the heap. However, in reality things are more elaborate.
Ques: 32 What’s the difference between struct and class in C#?
Ans:1. Structs cannot be inherited.
2. Structs are passed by value, not by reference.
3. Struct is stored on the stack, not the heap.
Ques: 33 To test a Web service you must create a windows application or Web application to consume this service?
Ans:The webservice comes with a test page and it provides HTTP-GET method to test.
Ques: 34 What is the transport protocol you use to call a Web service?
Ans: SOAP is the preferred protocol.
Ques: 35 Can you give an example of what might be best suited to place in the Application Start and Session Start subroutines?
Ans:This is where you can set the specific variables for the Application and Session objects.
Ques: 36 Where do you store the information about the user’s locale?
Ans:System.Web.UI.Page.Culture
Ques: 37 Where does the Web page belong in the .NET Framework class hierarchy?
Ans:System.Web.UI.Page
Ques: 38 Name two properties common in every validation control?
Ans:ControlToValidate property and Text property
Ques: 39 What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?
Ans:You must set the DataSource property and call the DataBind method.
Ques: 40 How can you provide an alternating color scheme in a Repeater control?
Ans:Use the AlternatingItemTemplate
Ques: 41 Which template must you provide, in order to display data in a Repeater control?
Ans:ItemTemplate
Ques: 42 Can you edit data in the Repeater control?
Ans:No, it just reads the information from its data source
Ques: 43 Which method do you invoke on the DataAdapter control to load your generated dataset with data?
Ans:The .Fill() method
Ques: 44 Describe the difference between inline and code behind.
Ans:Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.
Ques: 45 What’s a bubbled event?
Ans:When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.
Ques: 46 What is the role of global.asax.
Ans:Store global information about the application
Ques: 47 Can the action attribute of a server-side
Ques: 107 Explain Web Services?
Ans:Web services are programmable business logic components that provide access to functionality through the Internet. Web services are given the .asmx extension.Standard protocols like HTTP can be used to access them. Web services are based on the Simple Object Access Protocol (SOAP), which is an application of XML.In .Net FrameWork Web services convert your application in to Web Application.which published their functionality to whole world on internet.Web Services like a software system that designed to support interoperable machine-to-machine interaction over a Internet.
Ques: 108 What is Shallow Copy and Deep Copy in .NET?
Ans:Shallow copy:When a object creating and copying nonstatic field of the current object to the new object know as shallow copy.
If a field is a value type –> a bit-by-bit copy of the field is performed
a reference type –> the reference is copied but the referred object is not; therefore, the original object and its clone refer to the same object.
Deep copy:Deep cooy little same as shallow copy,deep copy the whole object and make a different object, it means it do not refer to the original object while in case of shallow copy the target object always refer to the original object and changes in target object also make changes in original object.
Ques: 109 What is CLR?
Ans:CLR(Common Language Runtime) provide Environment to debugg and run program and utility developed at the .Net FrameWork.CLR provide memory management, debugging, security, etc. The CLR is also known as Virtual Execution System (VES). The managed and unmanaged code both runs under CLR.Unmanaged code run through the Wrapered Classes.There are many system Utilities run under the CLR.
Ques: 110 Explain Namespace ?
Ans:There are many classes in Asp.Net.If Microsoft simply jumbled all the classes together, then you would never find anything. Microsoft divided the classes in the Framework into separate namespaces.All classes working with a file system located in Systen.Io Namespace. All classes working with SQL data base used System.Data.SqlClient Namespace.
The ASP.NET Framework gives you the most commonly used namespaces:
. System
. System.Collections
. System.Collections.Specialized
. System.Configuration
. System.Text
. System.Text.RegularExpressions
. System.Web
. System.Web.Caching
. System.Web.SessionState
. System.Web.Security
. System.Web.Profile
. System.Web.UI
. System.Web.UI.WebControls
. System.Web.UI.WebControls.WebParts
. System.Web.UI.HTMLControls
Ques: 111 What are the advantages and disadvantage of Using Cookies?
Ans:Advantage:
1.Cookies do not require any server resources since they are stored on the client.
2. Cookies are easy to implement.
3. Cookies to expire when the browser session ends (session cookies) or they can exist for a specified length of time on the computer (persistent cookies).
Disadvantage:
1. Users can delete a cookies.
2. Users browser can refuse cookies,so your code has to anticipate that possibility.
3. Cookies exist as plain text on the client machine and they may security risk as anyone can open and tamper with cookies.
Ques: 112 What is the difference between Session Cookies and Persistent Cookies?
Ans:When client broweses session cookie stored in a memmory.when browser closed session cookie lost.
//Code to create a UserName cookie containing the name David.
HttpCookie CookieObject = new HttpCookie("UserName", "David");
Response.Cookies.Add(CookieObject);
//Code to read the Cookie created above
Request.Cookies["UserName"].Value;
Persistent cookie same as the session cookie except that persistent cookie have expiration date.The expiration date indicates to the browser that it should write the cookie to the client’s hard drive.
//Code to create a UserName Persistent Cookie that lives for 10 days
HttpCookie CookieObject = new HttpCookie("UserName", "David");
CookieObject.Expires = DateTime.Now.AddDays(10);
Response.Cookies.Add(CookieObject);
//Code to read the Cookie created above
Request.Cookies["UserName"].Value;
Ques: 113 What are the steps to host a web application on a web server?
Ans:Step1.Set up a virtual folder for the application using IIS.
2. Copy the Web application to the virtual directory.
3. Adding the shared .NET components to the server’s global assembly cache (GAC).
4. Set the security permissions on the server to allow the application to access required resources.
Ques: 114 What happens when you make changes to an application’s Web.config file?
Ans:When make change in web.config file.IIS restarts application and automatically applies changes.This effect the Session state variable and effect the application,then user adversely affected.
Ques: 115 What is Globalization ?
Ans:The process to make a Application according to the user from multiple culture.The process involves translating the user interface in to many languages,like using the correct currency, date and time format, calendar, writing direction, sorting rules, and other issues.Accommodating these cultural differences for an application is called Globlization.
Three different ways to globalize web applications:
1.Detect and redirect approach
2.Run-time adjustment approach
3.Satellite assemblies approach
Ques: 116 What is the Difference between Compiler and Translator?
Ans:Compiler converet the program one computer language to another computer language.in other word high level language to low level language.
Traslator traslate one language to many other language like english to hindi,french etc.
Ques: 117 What is the Difference Between Compiler and Debugger ?
Ans:Compiler is a software or set of soetware that translate one computer Language to another computer.Most cases High level Programming Language to low level Programming Language.
Most of the time Program analyzed and examined error then Debugger used.Debugger is another program that is used for testing and debugging purpose of other programs. It will be able to tell where exactly in your application error occurred,and tell the where error occured.
Ques: 118 Types of Debbuger ?
Ans:Debugger is another program that is used for testing and debugging purpose of other programs. Most of the time it is using to analyze and examine error conditions in application. It will be able to tell where exactly in your application error occurred,
Two Types of Debbuger:
1.CorDBG – command-line debugger. To use CorDbg, you must compile the original C# file using the /debug switch.
2.DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR.
Ques: 119 Difference between Cookies and Session in Asp.Net ?
Ans:1.The main difference between cookies and sessions is that cookies are stored in the user’s browser, and sessions are not. This difference determines what each is best used for.
2.A cookie can keep information in the user’s browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie
3. Sessions are not reliant on the user allowing a cookie. They work instead like a token allowing access and passing information while the user has their browser open. The problem with sessions is that when you close your browser you also lose the session. So, if you had a site requiring a login, this couldn’t be saved as a session like it could as a cookie, and the user would be forced to re-login every time they visit.
Ques: 120 What is the structure of ASP.Net Pages ?
Ans:1.Directives:A directive controls how an ASP.NET page is compiled. The beginning of a directive is marked with the characters <%@ and the end of a directive is marked with the characters %>. A directive can appear anywhere within a page.A directive typically appears at the top of an ASP.NET page.
2.Code declaration block:A code declaration block contains all the application logic for your ASP.NET page and all the global variable declarations, subroutines, and functions. It must appear within a
<Script Runat="Server">
tag.
3.ASP.Net Controls:ASP.NET controls can be freely interspersed with the text and HTML content of a page. The only requirement is that the controls should appear within a
<form Runat= "Server">
tag. And, for certain tags such as
<span Runat="Server">
and
<ASP:Label Runat="Server"/>
, this requirement can be ignored without any dire consequences.
4.Code Render Blocks:If you need to execute code within the HTML or text content of your ASP.NET page, you can do so within code render blocks. The two types of code render blocks are inline code and inline expressions. Inline code executes a statement or series of statements. This type of code begins with the characters <% and ends with the characters %>.
5.Server side comments:You can add comments to your ASP.NET pages by using server-side comment blocks. The beginning of a server-side comment is marked with the characters <%-- and the end of the comment is marked with the characters --%>.
6.Server side include Directives:You can include a file in an ASP.NET page by using one of the two forms of the server-side include directive. If you want to include a file that is located in the same directory or in a subdirectory of the page including the file, you would use the following directive:
7.Literal text and html Tags:The final type of element that you can include in an ASP.NET page is HTML content. The static portion of your page is built with plain old HTML tags and text.
Ques: 121 Define File Name Extensions In Asp .net ?
Ans:Applications written in Asp .net have different files with different extension. native files generally have .aspx or .ascx extension . Web services have .asmx extension.
File name containing the business logic depend on the language that you are using. For Example a c# file have extension aspx.cs.
Ques: 122 What is ASp.net ?
Ans:ASP .NET built on .net framework. Asp .net is a web development tool. Asp .net is offered by Microsoft. We can built dynamic websites by using asp .net. Asp .net was first released in January 2002 with version 1.0 of the .net framework. It is the successor of Microsoft’s ASP. .NET Framework consists of many class libraries, support multiple languages and a common execution platform. Asp .net is a program run in IIS server. Asp .net is also called Asp+. Every element in Asp .net is treated as object and run on server. Asp .net is a event driven programming language. Most html tags are used by Asp .net. Asp .net allows the developer to build applications faster. Asp .net is a server side scripting.
Ques: 123 ASP.net Versions ?
Ans:ASP .NET version 1.0 was first released in January 2002
ASP .NET version 1.1 released in April 2003 (ASP .NET 2003)
ASP .NET version 2.0 released in November 2005 (ASP .NET 2005)
ASP .NET version 3.5 released in November 2007 (ASP .NET 2008)
Ques: 124 Difference bt ASP and asp.net?
Ans:1.Asp .net is compiled while asp is interpreted.
2.ASP is mostly written using VB Script and HTML. while asp .net can be written in C#, J# and VB etc.
3.Asp .net have 4 built in classes session , application , request response, while asp .net have more than 2000 built in classes.
4.ASP does not have any server side components whereas Asp .net have server side components such as Button , Text Box etc.
5.Asp does not have page level transaction while Asp .net have page level transaction.
ASP .NET pages only support one language on a single page, while Asp support multiple language on a single page.
6.Page functions must be declared as
<script runat=server>
in ASP. net . While in Asp page function is declared as <% %>.
Ques: 125 What is the difference between an EXE and a DLL?
Ans:DLL:Its a Dynamic Link Library .There are many entry points. The system loads a DLL into the context of an existing thread. Dll cannot Run on its own
EXE:Exe Can Run On its own.exe is a executable file.When a system launches new exe, a new process is created.The entry thread is called in context of main thread of that process.
Ques: 126 Difference Between Thread and Processs?
Ans:Process is a program in execution where thread is a seprate part of execution in the program.
Thread is a part of process. process is the collection of thread.
Ques: 127 How does cookies work in ASP.Net?
Ans:Using Cookies in web pages is very useful for temporarily storing small amounts of data, for the website to use. These Cookies are small text files that are stored on the user’s computer, which the web site can read for information; a web site can also write new cookies.
An example of using cookies efficiently would be for a web site to tell if a user has already logged in. The login information can be stored in a cookie on the user’s computer and read at any time by the web site to see if the user is currently logged in. This enables the web site to display information based upon the user’s current status – logged in or logged out.
Ques: 128 What is ASP.Net?
Ans:ASP Stands for Active server Pages.ASP used to create interacting web pages.
Ques: 129 What is Benefits of ASP.NET?
Ans:>>Simplified development:
ASP.NET offers a very rich object model that developers can use to reduce the amount of code they need to write.
>>Web services:
Create Web services that can be consumed by any client that understands HTTP and
XML, the de facto language for inter-device communication.
>>Performance:
When ASP.NET page is first requested, it is compiled and cached, or saved in memory, by
the .NET Common Language Runtime (CLR). This cached copy can then be re-used for
each subsequent request for the page. Performance is thereby improved because after
the first request, the code can run from a much faster compiled version.
>>Language independence
>>Simplified deployment
>>Cross-client capability
Ques: 130 How to create voting poll system in asp.net which allows user to see the results?Ques: 131 How to make User Control in ASP.net?
Ans:a)Add User Controll
write code:-
<hr color=red/> <center><H1><SPAN style="COLOR: #ff9999; TEXT-DECORATION: underline">BigBanyanTree.com</SPAN></H1></center> <hr Color=Green/>
b)In .aspx page:-
<%@ Register TagPrefix=a TagName="MyUserCtl" Src="~/WebUserControl.ascx"%>
c)Now use this :-
<a:MyUserCtl ID="tata" runat=server/>
Ques: 132 Write a program to show the Use of dataList in ASP.NET?
Ans:
<asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Both">
<HeaderTemplate>Employee Detailed</HeaderTemplate>
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "Empno") %>
<%#DataBinder.Eval(Container.DataItem, "Ename") %>
<%#DataBinder.Eval(Container.DataItem, "Sal") %>
</ItemTemplate>
Ques: 133 How to show data in HTML table using Repeater?
Ans:
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table border="10" width="100%" bgcolor=green style="width:100%" >
<tr>
<th>Empno</th> <th>Ename</th> <th>Sal</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container.DataItem, "Empno") %>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "Ename") %>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "Sal") %>
</td>
</tr>
</font>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</td>
<td style="width: 100px; height: 226px">
</td>
</tr>
</table>
Ques: 134 How Repeater is used in ASP.NET?
Ans:
<asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "Empno") %>
<%#DataBinder.Eval(Container.DataItem, "Ename") %>
<%#DataBinder.Eval(Container.DataItem, "Sal") %>
</ItemTemplate>
</asp:Repeater>
//the whole structure looks like this
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
Employee Detailed
</HeaderTemplate>
<ItemTemplate>
<font color=gray>
<%#DataBinder.Eval(Container.DataItem, "Empno") %>
<%#DataBinder.Eval(Container.DataItem, "Ename") %>
<%#DataBinder.Eval(Container.DataItem, "Sal") %>
</font>
</ItemTemplate>
<AlternatingItemTemplate>
<font color=green>
<%#DataBinder.Eval(Container.DataItem, "Empno") %>
<%#DataBinder.Eval(Container.DataItem, "Ename") %>
<%#DataBinder.Eval(Container.DataItem, "Sal") %>
</font>
</AlternatingItemTemplate>
<FooterTemplate>
Thanks
</FooterTemplate>
<SeparatorTemplate>
<hr/>
</SeparatorTemplate>
</asp:Repeater>
Ques: 135 Write a Program to Connect with dropdownlist in ASP.NET
Ans:
OleDbConnection x;
OleDbDataAdapter y;
DataSet z;
protected void Button1_Click(object sender, EventArgs e)
{
x = new OleDbConnection("Provider=msdaora;user id=scott;password=tiger");
x.Open();
y=new OleDbDataAdapter("select * from emp",x);
z = new DataSet();
y.Fill(z, "emp");
DropDownList1.DataSource = z;
DropDownList1.DataTextField = "ename";
DropDownList1.DataBind();
x.Close();
}
Ques: 136 Write a program to show data in Gridview in ASP.NET?
Ans:
OleDbConnection x;
OleDbDataAdapter y;
DataSet z;
protected void Button2_Click(object sender, EventArgs e)
{
x = new OleDbConnection("provider=msdaora;user id=scott;password=tiger");
x.Open();
y = new OleDbDataAdapter("select * from emp", x);
z = new DataSet();
y.Fill(z, "emp");
GridView1.DataSource = z.Tables["emp"];
GridView1.DataBind();
y.Dispose();
x.Close();
}
Ques: 137 Write a program to Delete Record in ASP.NET ?
Ans:
OleDbConnection x;
OleDbCommand y;
protected void Button1_Click(object sender, EventArgs e)
{
x = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=c:\\db1.mdb");
x.Open();
y = new OleDbCommand("delete from emp where empno=@p",x);
y.Parameters.Add("@p", TextBox1.Text);
y.ExecuteNonQuery();
Label1.Visible = true;
Label1.Text="Record Deleted";
y.Dispose();
x.Close();
}
Ques: 138 How to add Record in ASP.NET?
Ans:
OleDbConnection x;
OleDbCommand y;
protected void Button1_Click(object sender, EventArgs e)
{
x = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=c:\\db1.mdb");
x.Open();
y = new OleDbCommand("Insert into emp(empno,ename,sal) values(@p,@q,@r)", x);
y.Parameters.Add("@p", TextBox1.Text);
y.Parameters.Add("@q", TextBox2.Text);
y.Parameters.Add("@r", TextBox3.Text);
y.ExecuteNonQuery();
Label1.Visible = true;
Label1.Text="Record Addedd";
y.Dispose();
x.Close();
}
Ques: 139 Write a program to show connection to Excel in ASP.NET?
Ans:
OleDbConnection x;
OleDbCommand y;
OleDbDataReader z;
protected void Page_Load(object sender, EventArgs e)
{
x = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=c:\\book1.xls;Extended Properties=excel 8.0");
x.Open();
y = new OleDbCommand("select * from [sheet1$]", x);
z = y.ExecuteReader();
while (z.Read())
{
Response.Write("<li>");
Response.Write(z["ename"]);
}
z.Close();
y.Dispose();
x.Close();
}
Ques: 140 Write a program to show connection with Oracle in ASP.NET?
Ans:
OleDbConnection x;
OleDbCommand y;
OleDbDataReader z;
protected void Page_Load(object sender, EventArgs e)
{
x = new OleDbConnection("provider=msdaora;user id=scott;password=tiger");
x.Open();
y = new OleDbCommand("select * from emp", x);
z = y.ExecuteReader();
while (z.Read())
{
Response.Write("<li>");
Response.Write(z["ename"]);
}
z.Close();
y.Dispose();
x.Close();
}
Ques: 141 Write a program in ASP.NET to Show Data With Access?
Ans:Page_Load():-
OleDbConnection x;
OleDbCommand y;
OleDbDataReader z;
protected void Page_Load(object sender, EventArgs e)
{
x = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=c:\\db1.mdb");
x.Open();
y = new OleDbCommand("select * from emp", x);
z = y.ExecuteReader();
while (z.Read())
{
Response.Write(z["ename"]);
Response.Write("<hr>");
}
z.Close();
y.Dispose();
x.Close();
}
Ques: 142 Define Life Cycle of Page in ASP.NET?
Ans:
protected void Page_PreLoad(object sender, EventArgs e)
{
Response.Write("<br>"+"Page Pre Load");
}
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<br>" + "Page Load");
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
Response.Write("<br>" + "Page Complete");
}
protected void Page_PreRender(object sender, EventArgs e)
{
Response.Write("<br>" + "Page Pre Render");
}
protected void Page_Render(object sender, EventArgs e)
{
Response.Write("<br>" + "Pre Render");
}
protected void Page_PreInit(object sender, EventArgs e)
{
Response.Write("<br>" + "Page Pre Init");
}
protected void Page_Init(object sender, EventArgs e)
{
Response.Write("<br>" + "Page Init");
}
protected void Page_InitComplete(object sender, EventArgs e)
{
Response.Write("<br>" + "Page Pre Init Complete");
}
Ques: 143 DescribeWizard server control with example in Share Point?
Ans:This control enables you to build a sequence of steps that are displayed to the
end users side. It is alos used either display or gather information in small steps in system.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace LoisAndClark.WPLibrary
{
public class MyWP : WebPart
{
protected override void CreateChildControls()
{
Wizard objWizard = new Wizard();
objWizard.HeaderText = "Wizard Header";
for (int i = 1; i <= 6; i++)
{
WizardStepBase objStep = new WizardStep();
objStep.ID = "Step" + i;
objStep.Title = "Step " + i;
TextBox objText = new TextBox();
objText.ID = "Text" + i;
objText.Text = "Value for step " + i;
objStep.Controls.Add(objText);
objWizard.WizardSteps.Add(objStep);
}
this.Controls.Add(objWizard);
}
}
}
Ques: 144 What is BulletedList Control in Share Point. Give an example?
Ans:Bullet style allow u choose the style of the element that precedes the item.here u can choose numbers, squares, or circles.here child items can be rendered as plain text, hyperlinks, or buttons.
This example uses a custom image that requires to be placed in a virtual directory on the server.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace LoisAndClark.WPLibrary
{
public class MyWP : WebPart
{
protected override void CreateChildControls
{
BulletedList objBullist = new BulletedList();
objBullist.BulletStyle = BulletStyle.CustomImage;
objBullist.BulletImageUrl = @"/_layouts/images/rajesh.gif";
objBullist.Items.Add("First");
objBullist.Items.Add("Seciond");
objBullist.Items.Add("Third");
objBullist.Items.Add("Fourth");
this.Controls.Add(objBullist);
}
}
}
Ques: 145 How to create a SharePoint web part using File upload control.give example?
Ans:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace LoisAndClark.WPLibrary
{
public class MYWP : WebPart
{
FileUpload objFileUpload = new FileUpload();
protected override void CreateChildControls()
{
this.Controls.Add(new System.Web.UI.LiteralControl
("Select a file to upload:"));
this.Controls.Add(objFileUpload);
Button btnUpload = new Button();
btnUpload.Text = "Save File";
this.Load += new System.EventHandler(btnUpload_Click);
this.Controls.Add(btnUpload);
}
private void btnUpload_Click(object sender, EventArgs e)
{
string strSavePath = @"C:\temp\";
if (objFileUpload.HasFile)
{
string strFileName = objFileUpload.FileName;
strSavePath += strFileName;
objFileUpload.SaveAs(strSavePath);
}
else
{
//otherwise let the message show file was not uploaded.
}
}
}
}
Ques: 146 Print Hello World message using SharePoint in Asp.Net 2.0?
Ans:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace LoisAndClark.WPLibrary
{
public class MYWP : WebPart
{
protected override void CreateChildControls()
{
Content obj = new Content();
string str1 = obj.MyContent<string>("Hello World!");
this.Controls.Add(new System.Web.UI.LiteralControl(str1));
}
}
}
generic method shows that SharePoint site is running on .NET Framework
2.0, and the code of the generic method seems like this:
public string MyContent<MyType>(MyType arg)
{
return arg.ToString();
}
Ques: 147 How to Configure SMTP in asp .NET?
Ans:This example specifies SMTP parameters to send e-mail using a remote SMTP server and user that are importent. This program shows configuration process-
<system.net> <mailSettings> <smtp deliveryMethod="Network|PickupDirectoryFromIis|SpecifiedPickupDirec> <network defaultCredentials="true|false" from="r4r@fco.in" host="smtphost" port="26" password="password" userName="user"/> <specifiedPickupDirectory pickupDirectoryLocation="c:\pickupDirectory"/> </smtp> </mailSettings> </system.net>
Great series! In the ” ASP.NET Interview Questions ” I noticed that the link to “Download article as PDF” does not work properly (does not generate PDF). Correcting this would be deeply appreciated.
thanks
Hi Daniel,
There is hardware break up in the PDF Generation service I used. “Download article as PDF” will start working shortly.