Interview Question


What data type does the RangeValidator control support?
Integer,String and Date.
Suppose you want a certain ASP.NET function executed on MouseOver overa certain button. Where do you add an event handler?
It’s the Attributesproperty,
the Add function inside that property. So

btnSubmit.Attributes.Add("onMouseOver","someClientCode();")

A simple”Javascript:ClientCode();” in the button control of the .aspx page will attach the handler (javascript function)to the onmouseover event. 
Where does the Web page belong in the .NET Framework class hierarchy?
System.Web.UI.Page
Where do you store the information about the user’s locale?
System.Web.UI.Page.Culture
What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?
CodeBehind is relevant to Visual Studio.NET only.
What’s a bubbled event?
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 event handlers, allowing the main DataGrid event handler to take care of its constituents. 
Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.
inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension),the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe.
What’s the difference between Response.Write() andResponse.Output.Write()?
The latter one allows you to write formattedoutput.
What methods are fired during the page load?
Init() - when the pageis
instantiated, Load() - when the page is loaded into server memory,PreRender()
- the brief moment before the page is displayed to the user asHTML, Unload()
- when page finishes loading.
 

 

 

DataSets and DataAdapters:-

1)Difference between DataSets and DataAdapters?

Datasets store a copy of data from the database tables. However, Datasets can not directly retrieve data from Databases.
DataAdapters are used to link Databases with DataSets.DataSets and DataAdapters are used to display and manipulate data from databases


2)What is DataSet?
A Dataset is a in memory representation of a collection of Database objects including tables of a relational database scheme.
The dataset contains a collection of Tables, Relations, constraints etc.,

How to create xml file?

1)Select the table values from database
2)bind the values to Dataset
3)dataset to xmlDataDocument
4)Give the xml filename and save to current location.
[code]
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConn As String
'create connection to database table.
strConn = "USER=asd;PASSWORD=45646;SERVER=qwer;DATABASE=Emp"
Dim MySQL As String = "Select empno, empname from kk"
Dim MyConn As New SqlClient.SqlConnection(strConn)
Dim ds As DataSet = New DataSet()
Dim Cmd As New SqlClient.SqlDataAdapter(MySQL, MyConn)
'Fill the Table values to Dataset
Cmd.Fill(ds, "Emptbl")
'Bind the dataset values to xmldatadocument
Dim doc As New XmlDataDocument(ds)
doc.Save(MapPath("NewXMLName.xml"))
'This is where we are saving the data in an XML file NewXMLName.xml
End Sub
End Class

[/code]
The output look like
[code]
< NewDataSet >
< Emptbl>
< empno>3< /empno>
< empname>777
< /Emptbl>
< Emptbl>
< empno>344< /empno>
< empname>rrr677 < /empname>
< /Emptbl>
< Emptbl>
< empno>3< /empno>
< empname>ggg'D < /empname>
< /Emptbl>
< Emptbl>
< empno>4< /empno>
< empname>d < /empname>
< /Emptbl>
< Emptbl>
< /Emptbl>
< /NewDataSet>
[/code]

How to check whether any of the radiobutton selected or not?

[code]
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
string str;
if (RadioButtonList1.SelectedIndex != -1)
{
str = RadioButtonList1.SelectedItem.Text.ToString();
Response.Write(str);
}


}
}


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&>

<html xmlns="http://www.w3.org/1999/xhtml"&>
<head runat="server"&>
<title&>Untitled Page</title&>
</head&>
<body&>
<form id="form1" runat="server"&>
<div&>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"&>
<asp:ListItem&>ABC</asp:ListItem&>
<asp:ListItem&>AB</asp:ListItem&>
<asp:ListItem&>A</asp:ListItem&>
</asp:RadioButtonList&>
</div&>
</form&>
</body&>
</html&>

[/code]

How to convert DataReader to DataTable?

Just Drag and drop Grid view control to your web page

[code]
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ConvertDateReadertoTableUsingLoad();
}
private void ConvertDateReadertoTableUsingLoad()
{
SqlConnection conn = null;

string connString = "server=servername;database=databasename;uid=userid;password=password;";
conn = new SqlConnection(connString);
string query = "select * from Tablename";
SqlCommand cmd = new SqlCommand(query, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(dr);
conn.Close();
GridView1.DataSource = dt;
GridView1.DataBind();

}

}



[/code]

Confirmation message on button click in GridView?

Just Drag and drop Grid view control to your web page.
In Aspx.cs Page:-
[code]
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadGrid();
}
}
private void LoadGrid()
{
SqlConnection conn = null;
string connString = "server=servername;database=databasename;uid=userid;password=password;";
conn = new SqlConnection(connString);
string query = "select * from TableName";
SqlCommand cmd = new SqlCommand(query, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

dt.Load(dr);
conn.Close();
GridView1.DataSource = dt;
GridView1.DataBind();

}


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView vDataRowView = (DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button vBtnDelete = (Button)e.Row.FindControl("BtnDelete");
vBtnDelete.Attributes.Add("onclick", "return GridDelete()");

}


}
protected void BtnDelete_Click(object sender, EventArgs e)
{
Response.Write("Put your delete code here");


}
}

[/code]

In Aspx Page:-

[code]
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<script type="text/javascript">
function GridDelete()
{
if (confirm("Are you sure to delete this record permanently?") == true)
{
return true;
}
else
{
return false;
}
}
</script>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server"
onrowdatabound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="BtnDelete" runat="server" Text="Delete"
onclick="BtnDelete_Click" />
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
</form>
</body>
</html>


[/code]

How to pass parameter value to Stored Procedure ?

Just Drag and drop one grid view control on your web page.

In Aspx Page:-

[code]
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim command As New SqlCommand
Dim StrConnection As New SqlConnection("server=servername;database=databasename;uid=userid;pwd=password;") 'Give your connection string
Dim myDataReader As SqlDataReader
Dim Res As New StringBuilder
Dim da As SqlDataAdapter
command.Connection = StrConnection
command.Connection.Open()
command.CommandText = "ReturnMultipleValues" ' Give your sp name
Command.CommandType = CommandType.StoredProcedure
command.Parameters.AddWithValue("@ParameterName1", "YourValue")
command.Parameters.AddWithValue("@ParameterName2", "YourValue")
Dim dt As New DataTable
myDataReader = command.ExecuteReader()
dt.Load(myDataReader)
End Sub
End Class

[/code]

What are the main components of WCF?

The main components of WCF(Windows communication Foundation) are

1. Service class
2. Hosting environment
3. End point
More reference about this concept
http://www.dotnetfunda.com/articles/article221.aspx#WhatarethemaincomponentsofWCF

Difference between WCF and Web services?

Web Services

1.It Can be accessed only over HTTP
2.It works in stateless environment

WCF(Windows Communication Foundation)

WCF is flexible because its services can be hosted in different types of applications. The following lists several common scenarios for hosting WCF services:
IIS
WAS
Self-hosting
Managed Windows Service

How to use asp.net Multiview control?

The Multiview control acts as a stand alone Panel like control ,or can be a container for multiple panle like control called views.Using the new multiview control with the view control allows developers an easier way to toggle between panels.


take the below example
[code]

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
MultiView1.ActiveViewIndex = 0
End Sub

Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click
MultiView1.ActiveViewIndex = 1
End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
If txtPassword.Text <> "" And txtUsername.Text <> "" Then
Response.Redirect("")
Else
Response.Write("Enter Correct User Name and Password")
End If
End Sub

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Response.Write("Password has been sent to your mail id")
End Sub
End Class

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="LinkButton1" runat="server">Login Screen</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server">Forget Password</asp:LinkButton>
<br />
<asp:MultiView ID="MultiView1" runat="server">
<asp:View ID="View1" runat="server">
User Name
<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
<br />
Pass Word
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<br />

<asp:Button ID="Button2" runat="server" Text="Button" />
</asp:View>
<asp:View ID="View2" runat="server">
<br />
<br />
Email ID <asp:TextBox ID="txtFEmailid" runat="server"></asp:TextBox>

<asp:Button ID="Button3" runat="server" Text="Get Password" />
<br />
</asp:View>
</asp:MultiView>
</div>
</form>
</body>
</html>



[/code]

How to Create Text file using asp.net?

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Give your new file path
FileInfo t = new FileInfo("C:/WebSite10/test.txt");
StreamWriter Tex = t.CreateText();
//Enter your text with in writeline
Tex.WriteLine("How to create Text file using asp.net");
Tex.WriteLine("www.renganathan1984.blogspot.com");
//Add new line in your text file
Tex.Write(Tex.NewLine);
Tex.WriteLine("Trichy");
Tex.WriteLine("Thiruvellarai");

Tex.Close();
Response.Write("File Succesfully created!");
}

}