Purpose: How to use FileUploadControl Inside Update Pannel ASp.Net
.aspx page
------------------
.cs file
-----------
protected void SubmitButton_Click(object sender, EventArgs e)
{
Label SubmitButtonLabel2 = (Label)UpdatePanel1.FindControl("SubmitButtonLabel");
if (FileUpload1.HasFile)
{
string[] fileName = FileUpload1.FileName.Split('.');
string _extension = fileName[fileName.Length - 1];
if (_extension == "jpg" || _extension == "gif" || _extension == "bmp" || _extension == "png")
{
string _filepath = Server.MapPath("~/UPLOADIMAGE");
FileUpload1.PostedFile.SaveAs(_filepath + "\\" + FileUpload1.FileName);
SubmitButtonLabel2.Text = "File Accepted.";
}
else
{
SubmitButtonLabel2.Text = "File type not allowed. Please choose another.";
}
}
else
{
SubmitButtonLabel.Text = "Please select a file.";
}
}
Friday, August 28, 2009
Friday, July 17, 2009
Show the gridview header and footer when there is no records in database table
Purpose: How to show the gridview header and footer when there is no records in database table
Controls: Griedview
Job: Add TextBoxes to GridView Footer and apply property of GriedView showFooter=True;
Connection Object...
SqlConnection con = new SqlConnection("Data Source=SUSANT\\SQLEXPRESS ;Initial Catalog=Infitech; Integrated Security=True;");
DataTable dt = new DataTable();
//PageLoad Event..
protected void Page_Load(object sender, EventArgs e)
{
show_data();
}
// show_data() method to select all the values from database
public void show_data()
{
try
{
if (con.State==ConnectionState.Open)
{
con.Close();
}
con.Open();
DataSet ds = new DataSet();
string str = "select * from student";
SqlDataAdapter da = new SqlDataAdapter(str, con);
da.Fill(ds, "temp");
da.Fill(dt);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
else
{
ShowNoResultFound(dt,GridView1);
}
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
con.Dispose();
}
}
ShowNoResultFound() it will check if no record then it will create one error message...
private void ShowNoResultFound(DataTable source, GridView gv)
{
source.Rows.Add(source.NewRow()); // create a new blank row to the DataTable
// Bind the DataTable which contain a blank row to the GridView
gv.DataSource = source;
gv.DataBind();
// Get the total number of columns in the GridView to know what the Column Span should be
int columnsCount = gv.Columns.Count;
gv.Rows[0].Cells.Clear();// clear all the cells in the row
gv.Rows[0].Cells.Add(new TableCell()); //add a new blank cell
gv.Rows[0].Cells[0].ColumnSpan = columnsCount; //set the column span to the new added cell
//You can set the styles here
gv.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
gv.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red;
gv.Rows[0].Cells[0].Font.Bold = true;
//set No Results found to the new added cell
gv.Rows[0].Cells[0].Text = "NO RESULT FOUND!";
}
//Output if there is no record.....

Controls: Griedview
Job: Add TextBoxes to GridView Footer and apply property of GriedView showFooter=True;
Connection Object...
SqlConnection con = new SqlConnection("Data Source=SUSANT\\SQLEXPRESS ;Initial Catalog=Infitech; Integrated Security=True;");
DataTable dt = new DataTable();
//PageLoad Event..
protected void Page_Load(object sender, EventArgs e)
{
show_data();
}
// show_data() method to select all the values from database
public void show_data()
{
try
{
if (con.State==ConnectionState.Open)
{
con.Close();
}
con.Open();
DataSet ds = new DataSet();
string str = "select * from student";
SqlDataAdapter da = new SqlDataAdapter(str, con);
da.Fill(ds, "temp");
da.Fill(dt);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
else
{
ShowNoResultFound(dt,GridView1);
}
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
con.Dispose();
}
}
ShowNoResultFound() it will check if no record then it will create one error message...
private void ShowNoResultFound(DataTable source, GridView gv)
{
source.Rows.Add(source.NewRow()); // create a new blank row to the DataTable
// Bind the DataTable which contain a blank row to the GridView
gv.DataSource = source;
gv.DataBind();
// Get the total number of columns in the GridView to know what the Column Span should be
int columnsCount = gv.Columns.Count;
gv.Rows[0].Cells.Clear();// clear all the cells in the row
gv.Rows[0].Cells.Add(new TableCell()); //add a new blank cell
gv.Rows[0].Cells[0].ColumnSpan = columnsCount; //set the column span to the new added cell
//You can set the styles here
gv.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
gv.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red;
gv.Rows[0].Cells[0].Font.Bold = true;
//set No Results found to the new added cell
gv.Rows[0].Cells[0].Text = "NO RESULT FOUND!";
}
//Output if there is no record.....
Highlight Gridview row when mouse hover.
purpose: when mouse hover to girview row it will highlight the row..
controls: Add one gridview
connection object....
SqlConnection con = new SqlConnection("Data Source=SUSANT\\SQLEXPRESS ;Initial Catalog=Infitech; Integrated Security=True;");
//Page Load Event...
protected void Page_Load(object sender, EventArgs e)
{
show_data();
}
//select all the records from database..
public void show_data()
{
try
{
if (con.State==ConnectionState.Open)
{
con.Close();
}
con.Open();
DataSet ds = new DataSet();
string str = "select * from student";
SqlDataAdapter da = new SqlDataAdapter(str, con);
da.Fill(ds, "temp");
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
con.Dispose();
}
//gridview RowCreated Event....
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
string onmouseoverStyle = "this.style.backgroundColor='cyan'";
string onmouseoutStyle = "this.style.backgroundColor='white'";
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", onmouseoverStyle);
e.Row.Attributes.Add("onmouseout", onmouseoutStyle);
}
}
controls: Add one gridview
connection object....
SqlConnection con = new SqlConnection("Data Source=SUSANT\\SQLEXPRESS ;Initial Catalog=Infitech; Integrated Security=True;");
//Page Load Event...
protected void Page_Load(object sender, EventArgs e)
{
show_data();
}
//select all the records from database..
public void show_data()
{
try
{
if (con.State==ConnectionState.Open)
{
con.Close();
}
con.Open();
DataSet ds = new DataSet();
string str = "select * from student";
SqlDataAdapter da = new SqlDataAdapter(str, con);
da.Fill(ds, "temp");
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
con.Dispose();
}
//gridview RowCreated Event....
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
string onmouseoverStyle = "this.style.backgroundColor='cyan'";
string onmouseoutStyle = "this.style.backgroundColor='white'";
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", onmouseoverStyle);
e.Row.Attributes.Add("onmouseout", onmouseoutStyle);
}
}
Disable Back Date of Calender Control
Purpose: When we need user should not select back dates..
controls required:Add one Calender Control
protected void Page_Load(object sender, EventArgs e)
{
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date < DateTime.Now.Date)
{
e.Day.IsSelectable = false;
e.Cell.ForeColor = System.Drawing.Color.Gray;
}
}
}
controls required:Add one Calender Control
protected void Page_Load(object sender, EventArgs e)
{
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date < DateTime.Now.Date)
{
e.Day.IsSelectable = false;
e.Cell.ForeColor = System.Drawing.Color.Gray;
}
}
}
Saturday, May 30, 2009
Adding Country Name to DropDwonList..
Objective:
This small application will describe how easily we can get all the country names and how easily we can show all the country names in a dropdown list by using asp.net with C#..
Solution: step by step
Step 3: Go to Solution Explorer and add one folder named as App_Code

Hope u enjoy this code....
This small application will describe how easily we can get all the country names and how easily we can show all the country names in a dropdown list by using asp.net with C#..
Problem:
In any registration page we need user should select Country from the dropdown list and for this we have to add Country Name one by one.. I think it’s very difficult to remember all the Country Name and add to dropdown list…
In any registration page we need user should select Country from the dropdown list and for this we have to add Country Name one by one.. I think it’s very difficult to remember all the Country Name and add to dropdown list…
Solution: step by step
Step 1: Take one asp.net with C# application by using VS.Net 2.0;
Step 2: Design the form (Reg.aspx page)
Step 2: Design the form (Reg.aspx page)
Step 4: Inside App_Code ->Add New Item-> add one class named as GetCountryNames.cs
Step 5: code inside GetCountryNames.cs file
Step 6: Code for Reg.aspx.cs file..
Hope u enjoy this code....
Thursday, May 28, 2009
Disable Back button of Internet Explorer..
1: Purpose:
Some times we want user should not go back by clicking Back button of Internet Explorer. so here is the Java Script which we can write on master.aspx file in head section:
(Left Anchor Brkt) head (Right Anchor Brkt)
(Left Anchor Brkt) script language="javascript" type="text/javascript"(Right Anchor Brkt)
window.history.forward (1);
(Left Anchor Brkt) /script (Right Anchor Brkt)
(Left Anchor Brkt) /head (Right Anchor Brkt)
I m sorry to say the editor is not allowing Anchor bracket so u just implement..
2: Purpose:
Sometimes user should not go back after clicking logout Button..
protected void LinkLogoutBtn_Click(object sender, EventArgs e)
{
Session.Abandon();
Session["name"] = "";
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Redirect("logon.aspx");
}
Code description:
Here I write this code in Logout buton click event and when the user click logout i am clearing the cache and redirecting the user to Logon.aspx page..
Some times we want user should not go back by clicking Back button of Internet Explorer. so here is the Java Script which we can write on master.aspx file in head section:
(Left Anchor Brkt) head (Right Anchor Brkt)
(Left Anchor Brkt) script language="javascript" type="text/javascript"(Right Anchor Brkt)
window.history.forward (1);
(Left Anchor Brkt) /script (Right Anchor Brkt)
(Left Anchor Brkt) /head (Right Anchor Brkt)
I m sorry to say the editor is not allowing Anchor bracket so u just implement..
2: Purpose:
Sometimes user should not go back after clicking logout Button..
protected void LinkLogoutBtn_Click(object sender, EventArgs e)
{
Session.Abandon();
Session["name"] = "";
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Redirect("logon.aspx");
}
Code description:
Here I write this code in Logout buton click event and when the user click logout i am clearing the cache and redirecting the user to Logon.aspx page..
Tuesday, May 26, 2009
Difference between finalize and dispose method
Use of Finalize method in .NET:
.NET Garbage collector performs all the clean up activity of the managed objects or we can say GC call the Finalize () function automatically to destroy the object called implicit destroy., and so the finalize method is usually used to free up the unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc.
Use of the dispose() method in .NET:
The Dispose method in .NET belongs to IDisposable interface and it is best used to release unmanaged objects like File objects, Windows API objects, Database connection objects, COM objects etc from the memory. For betterPerformance we will use the dispose function explicitly.
Monday, May 25, 2009
Uploading filesize > 4MB using fileupload Control of ASP.Net
Problem:
While i try to upload .dat file which is more than 4MB i got one error message...
Reason:
In ASP.Net the default size of files uploaded by the FileUpload control is 4MB. So if you try to upload any file may be (.pdf, .doc, .wmv, dat..etc..) files larger than 4MB, it won't let you do so.
Solutions:
To do so, you need to change the default file size in machine.config.which is located in below pathC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG directory
//Add this code to machine.config file..
(use Left Anchor Brckt) httpRuntime
executionTimeout="90"
maxRequestLength="20000"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"/>
//or by adding one tag on web.config file
// Include the code below in your web application web.config
(use Left Anchor Brckt) system.web (use Right Anchor Brckt)
(use Left Anchor Brckt) httpRuntime executionTimeout="90"
maxRequestLength="20000"
useFullyQualifiedRedirectUrl="false"
requestLengthDiskThreshold="8192"/>
(left Anchor brkt) /system.web>
sorry to say this editor is not taking Anchor brackets so try to implement in code..
While i try to upload .dat file which is more than 4MB i got one error message...
Reason:
In ASP.Net the default size of files uploaded by the FileUpload control is 4MB. So if you try to upload any file may be (.pdf, .doc, .wmv, dat..etc..) files larger than 4MB, it won't let you do so.
Solutions:
To do so, you need to change the default file size in machine.config.which is located in below pathC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG directory
//Add this code to machine.config file..
(use Left Anchor Brckt) httpRuntime
executionTimeout="90"
maxRequestLength="20000"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"/>
//or by adding one tag on web.config file
// Include the code below in your web application web.config
(use Left Anchor Brckt) system.web (use Right Anchor Brckt)
(use Left Anchor Brckt) httpRuntime executionTimeout="90"
maxRequestLength="20000"
useFullyQualifiedRedirectUrl="false"
requestLengthDiskThreshold="8192"/>
(left Anchor brkt) /system.web>
sorry to say this editor is not taking Anchor brackets so try to implement in code..
Wednesday, May 20, 2009
Creating and Reading XML through ADO.Net...
Objective:
1: Creating one XML file taking data from my table
2: Reading that XML file to a gridview.
Design of form.

//Method for showing record in first grid view at the time of page_load.....
public void show_data()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=susant\\SQLEXPRESS; Integrated Security=True; Database=Infitech";
try
{
con.Open();
string str1 = "select * from student";
SqlDataAdapter da1 = new SqlDataAdapter(str1, con);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "temp");
GridView1.DataSource = ds1.Tables[0];
GridView1.DataBind();
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
//to show all the records present in table
show_data();
}
//button for creating the XML file...
protected void btnCreate_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=susant\\SQLEXPRESS; Integrated Security=True; Database=Infitech";
try
{
con.Open();
string str2 = "select * from student";
SqlDataAdapter da2 = new SqlDataAdapter(str2, con);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "temp");
//It will create one XML file in C:\MyXML.xml..
ds2.WriteXml("C:\\MyXML.xml");
Response.Write("Xml file created successfully...!!!");
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}
//Button for reading the XML file and showing in gridview2...
protected void btnRead_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=susant\\SQLEXPRESS; Integrated Security=True; Database=Infitech";
try
{
con.Open();
string str3 = "select * from student";
SqlDataAdapter da3 = new SqlDataAdapter(str3, con);
DataSet ds3 = new DataSet();
da3.Fill(ds3, "temp");
//It will create one XML file in C:\MyXML.xml..
ds3.ReadXml("C:\\MyXML.xml");
GridView2.DataSource = ds3.Tables[0];
GridView2.DataBind();
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}
1: Creating one XML file taking data from my table
2: Reading that XML file to a gridview.
Design of form.

//Method for showing record in first grid view at the time of page_load.....
public void show_data()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=susant\\SQLEXPRESS; Integrated Security=True; Database=Infitech";
try
{
con.Open();
string str1 = "select * from student";
SqlDataAdapter da1 = new SqlDataAdapter(str1, con);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "temp");
GridView1.DataSource = ds1.Tables[0];
GridView1.DataBind();
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
//to show all the records present in table
show_data();
}
//button for creating the XML file...
protected void btnCreate_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=susant\\SQLEXPRESS; Integrated Security=True; Database=Infitech";
try
{
con.Open();
string str2 = "select * from student";
SqlDataAdapter da2 = new SqlDataAdapter(str2, con);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "temp");
//It will create one XML file in C:\MyXML.xml..
ds2.WriteXml("C:\\MyXML.xml");
Response.Write("Xml file created successfully...!!!");
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}
//Button for reading the XML file and showing in gridview2...
protected void btnRead_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=susant\\SQLEXPRESS; Integrated Security=True; Database=Infitech";
try
{
con.Open();
string str3 = "select * from student";
SqlDataAdapter da3 = new SqlDataAdapter(str3, con);
DataSet ds3 = new DataSet();
da3.Fill(ds3, "temp");
//It will create one XML file in C:\MyXML.xml..
ds3.ReadXml("C:\\MyXML.xml");
GridView2.DataSource = ds3.Tables[0];
GridView2.DataBind();
}
catch (SqlException ex)
{
Response.Write(ex.Message);
}
finally
{
con.Close();
}
}
Wednesday, May 13, 2009
what are New features in ASP.Net3.5?
Microsoft released ASP.NET 3.5 on November 19, 2007. Along with it, was released Visual Studio 2008. This evolution from ASP.NET 2.0 to ASP.NET 3.5 is quiet gradual. ASP.NET 3.5 uses the same engine as that of ASP.NET 2.0, with some extra features added on top of it. In this article, we will explore the new features added to ASP.NET 3.5. This article assumes that you have been working on ASP.NET 2.0.
1: ASP.Net AJAX
In ASP.NET 2.0, ASP.NET AJAX was used as an extension to it. You had to download the extensions and install it. However in ASP.NET 3.5, ASP.NET AJAX is integrated into the .NET Framework, thereby making the process of building cool user interfaces easier and intuitive.
The integration between webparts and the update panel is much smoother. Another noticeable feature is that you can now add ASP.NET AJAX Control Extenders to the toolbox in VS2008.
2: New Controls:
The ListView and DataPager are new controls added along with a new datasource control called the LinqDataSource.
i) ListView
The ListView control is quiet flexible and contains features of the Gridview, Datagrid, Repeater and similar list controls available in ASP.NET 2.0. It provides the ability to insert, delete, page (using Data Pager), sort and edit data. However one feature of the ListView control that stands apart, is that it gives you a great amount of flexibility over the markup generated. So you have a complete control on how the data is to be displayed. You can now render your data without using thetag. You also get a rich set of templates with the ListView control.
1: ASP.Net AJAX
In ASP.NET 2.0, ASP.NET AJAX was used as an extension to it. You had to download the extensions and install it. However in ASP.NET 3.5, ASP.NET AJAX is integrated into the .NET Framework, thereby making the process of building cool user interfaces easier and intuitive.
The integration between webparts and the update panel is much smoother. Another noticeable feature is that you can now add ASP.NET AJAX Control Extenders to the toolbox in VS2008.
2: New Controls:
The ListView and DataPager are new controls added along with a new datasource control called the LinqDataSource.
i) ListView
The ListView control is quiet flexible and contains features of the Gridview, Datagrid, Repeater and similar list controls available in ASP.NET 2.0. It provides the ability to insert, delete, page (using Data Pager), sort and edit data. However one feature of the ListView control that stands apart, is that it gives you a great amount of flexibility over the markup generated. So you have a complete control on how the data is to be displayed. You can now render your data without using the
Partial Classes with C# 2.0
With C# 2.0 it is possible to split definition of classes, interfaces and structures over more than one files.This feature allows you to do a couple of fancy things like:
1- More than one developer can simultaneously write the code for the class.
2- You can easily write your code (for extended functionality) for a VS.NET generated class. This will allow you to write the code of your own need without messing with the system generated code.
There are a few things that you should be careful about when writing code for partial classes:
1- All the partial definitions must precede with the key word "Partial".
2- All the partial types meant to be the part of same type must be defined within a same assembly and module.
3- Method signatures (return type, name of the method, and parameters) must be unique for the aggregated typed (which was defined partially). i.e. you can write default constructor in two separate definitions for a particular partial class.
1- More than one developer can simultaneously write the code for the class.
2- You can easily write your code (for extended functionality) for a VS.NET generated class. This will allow you to write the code of your own need without messing with the system generated code.
There are a few things that you should be careful about when writing code for partial classes:
1- All the partial definitions must precede with the key word "Partial".
2- All the partial types meant to be the part of same type must be defined within a same assembly and module.
3- Method signatures (return type, name of the method, and parameters) must be unique for the aggregated typed (which was defined partially). i.e. you can write default constructor in two separate definitions for a particular partial class.
Diff between SQLServer 2000 and SQLServer 2005?
1. In SQL Server 2000 the Query Analyzer and Enterprise Manager are separate, whereas in SQL Server 2005 both were combined as Management Studio.
2. In Sql 2005,the new datatype XML is used,whereas in Sql 2000 there is no such datatype
3. In Sql server2000 we can create 65,535 databases,whereas in Sql server2005 2(pow(20))-1 databases can be created.
4. Reporting service is available in 2005
2. In Sql 2005,the new datatype XML is used,whereas in Sql 2000 there is no such datatype
3. In Sql server2000 we can create 65,535 databases,whereas in Sql server2005 2(pow(20))-1 databases can be created.
4. Reporting service is available in 2005
What is a Typed Dataset in ADO.NET?
Typed DataSet - When a created DataSet derives from the DataSet class, that applies the information contained in the XSD to create a Typed class, this DataSet is said to be a Typed Dataset. Information from the schema which comprises the tables, columns, and rows is created and compiled to a new DataSet derived from the XSD. The Typed DataSet class features all functionality of the DataSet class. This may be used with methods that take an instance of the DataSet class as a parameter.
Note that an UnTyped DataSet does not have any schema. It is exposed simply as a mere collection.
How to create a Typed DataSet?
Write click your project in the Solution Explorer.Click Add New Item.Select DataSet.This adds a new XSD to the project. The schema created may be viewed as an XML. When this xsd file is compiled, two files are created by Visual Studio. The first file that contains the .vb or .cs extension contains the information about the proxy class. This class contains methods & properties that are required to access the database data. The second file has an extension xsx and this contains information about the layout of the XSD.
Note that an UnTyped DataSet does not have any schema. It is exposed simply as a mere collection.
How to create a Typed DataSet?
Write click your project in the Solution Explorer.Click Add New Item.Select DataSet.This adds a new XSD to the project. The schema created may be viewed as an XML. When this xsd file is compiled, two files are created by Visual Studio. The first file that contains the .vb or .cs extension contains the information about the proxy class. This class contains methods & properties that are required to access the database data. The second file has an extension xsx and this contains information about the layout of the XSD.
What is Diffgram in ADO.NET? When do we use Diffgram?
A DiffGram is an XML format. It is used to identify current and original versions of data elements. A DataSet may use a DiffGram format to load and persist the contents, and further to serialize its contents for porting across a network connection. Whenever a DataSet is written as a DiffGram, the DataSet populates the DiffGram with all the important information to accurately recreate the contents. Note that schema of the DataSet is not recreated. This includes column values from both the Current and the Original row versions, row error information, and row order.
What are the default values in C#.Net?
Type Default Value
bool : false
int : 0
double : 0
string : null
char : '\0'
Reference Type : null
bool : false
int : 0
double : 0
string : null
char : '\0'
Reference Type : null
What is the use of System.Environment class in ASP.Net?
The class System.Environment is used to retrieve information about the operating system. Some of the static members of this class are as follows:
1) Environment.OSVersion - Gets the version of the operating system
2) Environment.GetLogicalDrives() - method that returns the drives
3) Environment.Version - returns the .NET version running the application
4) Environment.MachineName - Gets name of the current machine
5) Environment.Newline - Gets the newline symbol for the environment
6) Environment.ProcessorCount - returns number of processors on current machine
7) Environment.SystemDirectory - returns complete path to the System Directory
8) Environment.UserName - returns name of the entity that invoked the application
1) Environment.OSVersion - Gets the version of the operating system
2) Environment.GetLogicalDrives() - method that returns the drives
3) Environment.Version - returns the .NET version running the application
4) Environment.MachineName - Gets name of the current machine
5) Environment.Newline - Gets the newline symbol for the environment
6) Environment.ProcessorCount - returns number of processors on current machine
7) Environment.SystemDirectory - returns complete path to the System Directory
8) Environment.UserName - returns name of the entity that invoked the application
Tuesday, May 12, 2009
Difference between the FormView and the DetailsView in ASP.Net
DetailsView control is similar to that of the GridView control.
However, the DetailsView control does not support a selection event, because the current record is always the selected item.
The DetailsView control does not support sorting.
DetailsView control uses a tabular layout where each field of the record is displayed as a row of its own.
The difference between the FormView and the DetailsView controls is that the DetailsView control uses a tabular layout where each field of the record is displayed as a row of its own. In contrast, the FormView control does not specify a pre-defined layout for displaying the record. Instead, you create a template containing controls to display individual fields from the record. The template contains the formatting, controls, and binding expressions used to create the form
However, the DetailsView control does not support a selection event, because the current record is always the selected item.
The DetailsView control does not support sorting.
DetailsView control uses a tabular layout where each field of the record is displayed as a row of its own.
The difference between the FormView and the DetailsView controls is that the DetailsView control uses a tabular layout where each field of the record is displayed as a row of its own. In contrast, the FormView control does not specify a pre-defined layout for displaying the record. Instead, you create a template containing controls to display individual fields from the record. The template contains the formatting, controls, and binding expressions used to create the form
Types of objects in ASP.Net
There are 7 objects in Asp.Net
1. Request,
2. Response,
3. session,
4. Application,
5. Server,
6. AspError,
7. Object context
1. Request,
2. Response,
3. session,
4. Application,
5. Server,
6. AspError,
7. Object context
Get the extension of file in .NET
Below code shows how to get the file extension in .NET using C# or VB.net. We may need to check the file extension to validate type of file while uploading. System.IO.Path provide GetExtension() method and will return you the extension of the input file.
C# code sample
string extension = Path.GetExtension("c:\\myFile.jpg");
in Vb.NET code example
Dim extension As String = Path.GetExtension("c:\myFile.zip")
C# code sample
string extension = Path.GetExtension("c:\\myFile.jpg");
in Vb.NET code example
Dim extension As String = Path.GetExtension("c:\myFile.zip")
Difference between String and string.
"string" is a keyword; you can't use "string" as an identifier.
"String" is not a keyword, and you can use it as an identifier:
"String" is not a keyword, and you can use it as an identifier:
Monday, May 11, 2009
Directives in asp.net..
1) @ Assembly: Links an assembly to the current page or user control declaratively.
2) @ Control : Defines control-specific attributes used by the ASP.NET page parser and compiler and can be included only in .ascx files (user controls).
3) @ Implements : Indicates that a page or user control implements a specified .NET Framework interface declaratively.
4) @ Import: Imports a namespace into a page or user control explicitly.
5) @ Master: Identifies a page as a master page and defines attributes used by the ASP.NET page parser and compiler and can be included only in .master files.
6) @ MasterType : Defines the class or virtual path used to type the Master property of a page.
7) @ OutputCache : Controls the output caching policies of a page or user control declaratively.
8) @ Page : Defines page-specific attributes used by the ASP.NET page parser and compiler and can be included only in .aspx files.
9) @ PreviousPageType: Creates a strongly typed reference to the source page from the target of a cross-page posting.
10) @ Reference : Links a page, user control, or COM control to the current page or user control declaratively.
11) @ Register: Associates aliases with namespaces and classes, which allow user controls and custom server controls to be rendered when included in a requested page or user control
2) @ Control : Defines control-specific attributes used by the ASP.NET page parser and compiler and can be included only in .ascx files (user controls).
3) @ Implements : Indicates that a page or user control implements a specified .NET Framework interface declaratively.
4) @ Import: Imports a namespace into a page or user control explicitly.
5) @ Master: Identifies a page as a master page and defines attributes used by the ASP.NET page parser and compiler and can be included only in .master files.
6) @ MasterType : Defines the class or virtual path used to type the Master property of a page.
7) @ OutputCache : Controls the output caching policies of a page or user control declaratively.
8) @ Page : Defines page-specific attributes used by the ASP.NET page parser and compiler and can be included only in .aspx files.
9) @ PreviousPageType: Creates a strongly typed reference to the source page from the target of a cross-page posting.
10) @ Reference : Links a page, user control, or COM control to the current page or user control declaratively.
11) @ Register: Associates aliases with namespaces and classes, which allow user controls and custom server controls to be rendered when included in a requested page or user control
Difference between string and string builder.
1. String is immutable where is string builder is mutable..
2.In string Builder, automatically increase and decrease size of string object whenever add elements and delete elements .Where in string , it is fixed size…...
3.StringBuilder can performed a insert(),Delete(),Reverse(),Sort() operations etc and we can create multiple instances .Where as String , It can't perform .
4. StringBuilder takes enough memory for variable .Where, as String can't perfume
2.In string Builder, automatically increase and decrease size of string object whenever add elements and delete elements .Where in string , it is fixed size…...
3.StringBuilder can performed a insert(),Delete(),Reverse(),Sort() operations etc and we can create multiple instances .Where as String , It can't perform .
4. StringBuilder takes enough memory for variable .Where, as String can't perfume
Differences between Datagrid, Datalist and Repeater
1. Datagrid has paging while Datalist doesnt.
2. Datalist has a property called repeat. Direction = vertical/horizontal. (This is of great help in designing layouts). This is not there in Datagrid.
3. A repeater is used when more intimate control over html generation is required.
4. When only checkboxes/radiobuttons are repeatedly served then a checkboxlist or radiobuttonlist are used as they involve fewer overheads than a Datagrid.The Repeater repeats a chunk of HTML you write, it has the least functionality of the three. DataList is the next step up from a Repeater; accept you have very little control over the HTML that the control renders. DataList is the first of the three controls that allow you Repeat-Columns horizontally or vertically. Finally, the DataGrid is the motherload. However, instead of working on a row-by-row basis, you’re working on a column-by-column basis. DataGrid caters to sorting and has basic paging for your disposal. Again you have little contro, over the HTML. NOTE: DataList and DataGrid both render as HTML tables by default. Out of the 3 controls, I use the Repeater the most due to its flexibility w/ HTML. Creating a Pagination scheme isn't that hard, so I rarely if ever use a DataGrid. Occasionally I like using a DataList because it allows me to easily list out my records in rows of three for instance.
2. Datalist has a property called repeat. Direction = vertical/horizontal. (This is of great help in designing layouts). This is not there in Datagrid.
3. A repeater is used when more intimate control over html generation is required.
4. When only checkboxes/radiobuttons are repeatedly served then a checkboxlist or radiobuttonlist are used as they involve fewer overheads than a Datagrid.The Repeater repeats a chunk of HTML you write, it has the least functionality of the three. DataList is the next step up from a Repeater; accept you have very little control over the HTML that the control renders. DataList is the first of the three controls that allow you Repeat-Columns horizontally or vertically. Finally, the DataGrid is the motherload. However, instead of working on a row-by-row basis, you’re working on a column-by-column basis. DataGrid caters to sorting and has basic paging for your disposal. Again you have little contro, over the HTML. NOTE: DataList and DataGrid both render as HTML tables by default. Out of the 3 controls, I use the Repeater the most due to its flexibility w/ HTML. Creating a Pagination scheme isn't that hard, so I rarely if ever use a DataGrid. Occasionally I like using a DataList because it allows me to easily list out my records in rows of three for instance.
what is Event bubbling in .Net?
Server control like (Repeater, DataList, and DataGrid). They can have child control. Suppose Datalist have a Dropdown List as child control. The DropdownList cant raise their event directly rather they pass the event to container parent which passed to the page (within ItemTemplates) event. As the child control send there events to parent this is termed as event bubbling.
What is delegates in C#.?
· Delegates are type safe function pointers
· It exhibits the property of a class and a function
· They can access static as well as member functions
· An event is a message sent by an object to indicate the occurrence of an action
· A delegate is a class that can hold reference to a method. It has a signature (unlike class). It can hold reference only to method that matches its signature. Therefore, delegate is a type safe function pointer.
· By default, it needs two parameters, viz; source that raised the event + data for the event
· Event delegates are multicast; i.e they can hold reference to more than one event handling methods
· It exhibits the property of a class and a function
· They can access static as well as member functions
· An event is a message sent by an object to indicate the occurrence of an action
· A delegate is a class that can hold reference to a method. It has a signature (unlike class). It can hold reference only to method that matches its signature. Therefore, delegate is a type safe function pointer.
· By default, it needs two parameters, viz; source that raised the event + data for the event
· Event delegates are multicast; i.e they can hold reference to more than one event handling methods
Difference between Global.asax and Web.Config?
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.
Difference between Interface and Abstract class:
1. Interface comes in Inheritance chain while Abstract not
2. One class can inherit multiple interfaces but it can't
inherit multiple abstract class
3. Abstract class can have concert method but interface
can't.
4.An abstract class can contain fields, constructors, or
destructors and implement properties. An interface can not
contain fields, constructors, or destructors and it has
only the property's signature but no implementation.
5.Abstract classes are faster than interfaces.
2. One class can inherit multiple interfaces but it can't
inherit multiple abstract class
3. Abstract class can have concert method but interface
can't.
4.An abstract class can contain fields, constructors, or
destructors and implement properties. An interface can not
contain fields, constructors, or destructors and it has
only the property's signature but no implementation.
5.Abstract classes are faster than interfaces.
What are shared (VB.Net) / Static(C#) variables?
• Static/shared classes cannot be inherited.
• We can’t create object of static class.
• Static/shared classes can only contain static members.
• Static/shared classes can have only static Constructors.
• Static classes are sealed.
• We can’t create object of static class.
• Static/shared classes can only contain static members.
• Static/shared classes can have only static Constructors.
• Static classes are sealed.
Difference between CLASS & Structure:
i) A structure is a value type, while a class is a reference type.
ii) When we instantiate a class, memory will be allocated on the heap. When structure gets initiated, it gets memory on the stack.
iii) Classes can have explicit parameter less constructors. But structs cannot have this.
iv) Classes support inheritance. But there is no inheritance for structs.
v) We can assign null variable to class. But we cannot assign null to a struct .
vi) We can declare a destructor in class but can not in struct.
ii) When we instantiate a class, memory will be allocated on the heap. When structure gets initiated, it gets memory on the stack.
iii) Classes can have explicit parameter less constructors. But structs cannot have this.
iv) Classes support inheritance. But there is no inheritance for structs.
v) We can assign null variable to class. But we cannot assign null to a struct .
vi) We can declare a destructor in class but can not in struct.
What is the difference between Server.Transfer and Response.Redirect?
Server.Transfer: It transfers execution from the first page to the second page on the server. As far as the browser client is concerned, it made one request and the initial page is the one responding with content. The benefit of this approach is one less round trip to the server from the client browser. Also, any posted form variables and query string parameters are available to the second page as well.
page must be in same server and an ,aspx file
This method avoids un-necessary round trips
Response.Redirect: This tells the browser that the requested page can be found at a new location. The browser then initiates another request to the new page loading its contents in the browser. This results in two requests by the browser.
1: we can pass query string vales
2: we can connect to non .aspx page(ex. .html)
3. we can connect to resource to any server.
page must be in same server and an ,aspx file
This method avoids un-necessary round trips
Response.Redirect: This tells the browser that the requested page can be found at a new location. The browser then initiates another request to the new page loading its contents in the browser. This results in two requests by the browser.
1: we can pass query string vales
2: we can connect to non .aspx page(ex. .html)
3. we can connect to resource to any server.
Difference between DLL & EXE
1. In shortcut .exe is an executable file & DLL (Dynamic Link Library) is not an executable file.
2. DLL is an in-process server while exe is a out-process server it means DLL works within the thread of application while exe works after creating its own thread.
3. If DLL fails the application became fail if exe fails DLL doesn’t fail because it’s not work within the thread of application but the part of the exe could not work properly.
4. An EXE is visible to the system as a regular Win32 executable. Its entrypoint refers to a small loader, which initializes the .NET runtime and tellsit to load and execute the assembly contained in the EXE.
5. A DLL is visible to the system as a Win32 DLL but most likely without anyentry points. The .NET runtime stores information about the containedassembly in its own header.
2. DLL is an in-process server while exe is a out-process server it means DLL works within the thread of application while exe works after creating its own thread.
3. If DLL fails the application became fail if exe fails DLL doesn’t fail because it’s not work within the thread of application but the part of the exe could not work properly.
4. An EXE is visible to the system as a regular Win32 executable. Its entrypoint refers to a small loader, which initializes the .NET runtime and tellsit to load and execute the assembly contained in the EXE.
5. A DLL is visible to the system as a Win32 DLL but most likely without anyentry points. The .NET runtime stores information about the containedassembly in its own header.
What is an assembly?
· Assemblies are the building blocks of .NET Framework applications
· An assembly is a collection of one or more files and one of them (DLL or EXE)
· An assembly is created whenever a DLL is built
· There are two types of assembly
· A: Privae Assembly: stored in directory or sub directory. It can be used by a single application
· B: Shared Assembly: Stored in GAC can be shared by many application must have a strong name.
· An assembly is a collection of one or more files and one of them (DLL or EXE)
· An assembly is created whenever a DLL is built
· There are two types of assembly
· A: Privae Assembly: stored in directory or sub directory. It can be used by a single application
· B: Shared Assembly: Stored in GAC can be shared by many application must have a strong name.
What is the Microsoft Intermediate Language (MSIL)?
MSIL is the CPU-independent instruction set, into which .NET Framework programs are compiled. It contains instructions for loading, storing, initializing, and calling methods on objects. Combined with metadata and the CTS, MSIL allows for true cross-language integration. Prior to execution, MSIL is converted to machine code. It is not interpreted.
What is Base Class Library?
The .NET Framework provides a set of hierarchical objects, broken down by functionality, called the Base Class Libraries. The classes provide a set of common OO interfaces that are accessible from any .NET language.
The BCL is divided into namespaces, which define a naming scheme for classes, such as Web classes, Data classes, Windows Forms, XML classes, Enterprise services, and System classes.
By implementing a naming convention, it is easy to separate the class functionalities into categories. For example, the System namespace has the following top-level Data classes-
System. Data
System.Data.Common
System.Data.OLEDB
System.Data.SqlClient
System.Data.SqlTypes
Each of these namespaces is broken down further into more granular classes, which define the methods, fields, structures, enumerations, and interfaces that are provided by each type. The System class provides the base services that all .NET languages will include-such as IO, arrays, collections, security, and globalization.
The BCL is divided into namespaces, which define a naming scheme for classes, such as Web classes, Data classes, Windows Forms, XML classes, Enterprise services, and System classes.
By implementing a naming convention, it is easy to separate the class functionalities into categories. For example, the System namespace has the following top-level Data classes-
System. Data
System.Data.Common
System.Data.OLEDB
System.Data.SqlClient
System.Data.SqlTypes
Each of these namespaces is broken down further into more granular classes, which define the methods, fields, structures, enumerations, and interfaces that are provided by each type. The System class provides the base services that all .NET languages will include-such as IO, arrays, collections, security, and globalization.
What is the common type system (CTS)?
.Net framework supports multiple languages, and different language defines their primitives’ data types in different formats. For examples:
C# defines and integer variable : int i;
Where as VB.Net defines an integer variable: Dim i as integer
Microsoft tries to convert these data types into a generic data types. So that different codes written in different languages code are converted into language independent code, due to this CTS is created.
CTS contain different data type’s specification to be used in our code. For example: the primitives’ integer data type is known as Int32, in CTS. All data types are derived from object data types from which the value types and reference types are defined.
C# defines and integer variable : int i;
Where as VB.Net defines an integer variable: Dim i as integer
Microsoft tries to convert these data types into a generic data types. So that different codes written in different languages code are converted into language independent code, due to this CTS is created.
CTS contain different data type’s specification to be used in our code. For example: the primitives’ integer data type is known as Int32, in CTS. All data types are derived from object data types from which the value types and reference types are defined.
What is the common language runtime (CLR)?
The common language runtime is the execution engine for .NET Framework applications. It provides a number of services, including the following:
i) Code management (loading and execution)
ii) Application memory isolation.
iii) Version control.
iv) Conversion of IL to native code.
v) Access to metadata (enhanced type information)
vi) Garbage collection
vii) Enforcement of code access security.
viii) Exception handling, including cross-language exceptions
ix) Interoperation between managed code.
x) Support for developer services (profiling, debugging, and so on)
i) Code management (loading and execution)
ii) Application memory isolation.
iii) Version control.
iv) Conversion of IL to native code.
v) Access to metadata (enhanced type information)
vi) Garbage collection
vii) Enforcement of code access security.
viii) Exception handling, including cross-language exceptions
ix) Interoperation between managed code.
x) Support for developer services (profiling, debugging, and so on)
Difference Between StoredProcedure and UserDefinedFunctions(UDF)
1.Procedure can return 0 or n values whereas functions can return a single value which is mandatory.
2.Procedure can have input and output parameter whereas functions can have only input type of parameters.
3.Procedure can be used for select command as well as for DML commands(Insert,Delete,Update) and DDL Commands (Create,Drop) while functions can be used for only select commands.
4.Functions can be called from Procedure while Procedure can not be called from Functions.
5.Exceptions can be handled by try-catch block in Procedure whereas try-catch block can not be used in functions.
6.We can go for transaction management in procedure whereas we can't go in function. 7.Functions are normally used for computations where as procedures are normally used for executing business logic.
8.Stored procedure returns always integer value by default zero. where as function return type could be scalar or table or table values
9.Stored procedure is precompiled execution plan where as functions are not.
10.A procedure may modify an object where a function can only return a value The RETURN statement immediately completes the execution of a subprogram and returns control to the caller.
11.You can call stored procedure directly from other programing language (like dot net) but Functions have to be used in Query's
12.We can write commit statements in procedures but can not write in Functions.
2.Procedure can have input and output parameter whereas functions can have only input type of parameters.
3.Procedure can be used for select command as well as for DML commands(Insert,Delete,Update) and DDL Commands (Create,Drop) while functions can be used for only select commands.
4.Functions can be called from Procedure while Procedure can not be called from Functions.
5.Exceptions can be handled by try-catch block in Procedure whereas try-catch block can not be used in functions.
6.We can go for transaction management in procedure whereas we can't go in function. 7.Functions are normally used for computations where as procedures are normally used for executing business logic.
8.Stored procedure returns always integer value by default zero. where as function return type could be scalar or table or table values
9.Stored procedure is precompiled execution plan where as functions are not.
10.A procedure may modify an object where a function can only return a value The RETURN statement immediately completes the execution of a subprogram and returns control to the caller.
11.You can call stored procedure directly from other programing language (like dot net) but Functions have to be used in Query's
12.We can write commit statements in procedures but can not write in Functions.
Subscribe to:
Posts (Atom)
