Tolal:147 Click:
1
2 3 4 5 6 7 8
ASP.net Interview Questions And Answers
Page 1
Ques: 1 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>
Ques: 2 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: 3 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: 4
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: 5 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: 6 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: 7 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: 8
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: 9
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: 10 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();
}
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: 11 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: 12 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: 13 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: 14 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: 15 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>
Ans:
dfd
Ques: 16 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: 17 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: 18 How to create voting poll system in asp.net which allows user to see the results?
Ques: 19 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: 20 What is ASP.Net?
Ans:
ASP Stands for Active server Pages.ASP used to create interacting web pages.
Goto Page:
1
2 3 4 5 6 7 8
ASP.net Objective
ASP.net Objective Questions And Answers
ASP.net Interview Questions And Answers
ASP.net Interview Questions And Answers
R4R,ASP.net Objective, ASP.net Subjective, ASP.net Interview Questions And Answers,ASP.net,ASP.net Interview,ASP.net Questions ,ASP.net Answers