Browser Detection Using Javascript

<%@ 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>Browser Detection Using Javascript</title>
    <script type="text/javascript">
   
 function Browser()
  {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) alert('Opera');
if (agt.indexOf("staroffice") != -1) alert('Star Office');
if (agt.indexOf("webtv") != -1) alert('WebTV');
if (agt.indexOf("beonex") != -1) alert('Beonex');
if (agt.indexOf("chimera") != -1) alert('Chimera');
if (agt.indexOf("netpositive") != -1) alert('NetPositive');
if (agt.indexOf("phoenix") != -1) alert('Phoenix');
if (agt.indexOf("firefox") != -1) alert('Firefox');
if (agt.indexOf("safari") != -1) alert('Safari');
if (agt.indexOf("skipstone") != -1) alert('SkipStone');
if (agt.indexOf("msie") != -1) alert('Internet Explorer');
if (agt.indexOf("netscape") != -1) alert('Netscape');
if (agt.indexOf("mozilla/5.0") != -1) alert('Mozilla');
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}
</script>
</head>

<body onload="return Browser();">
    <form id="form1" runat="server">
    <div>
      
    </div>
    </form>
</body>
</html>

C# Interview Question :-

C# Interview Question :-

1)Virtual function in c# with example?

Virtual functions implement the concept of polymorphism are the same as in C#, except that you use the override keyword with the virtual function implementaion in the child class. The parent class uses the same virtual keyword. Every class that overrides the virtual method will use the override keyword.


class Shape{    public virtual void Draw()    {        Console.WriteLine("Shape.Draw")    ;    }}class Rectangle : Shape{    public override void Draw()    {        Console.WriteLine("Rectangle.Draw");    }}

2)How to Do File Exception Handaling in C#?
Exception handling is an in built mechanism in .NET framework to detect and handle run time errors. The .NET framework contains lots of standard exceptions. The exceptions are anomalies that occur during the execution of a program. They can be because of user, logic or system errors. If a user do not provide a mechanism to handle these anomalies, the .NET run time environment provide a default mechanism, which terminates the program execution


 3)What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.

4)What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The first one performs a deep copy of the array, the second one is shallow.

5)What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?
 A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.


6)Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.

7)What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft.
OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines

8)What is a pre-requisite for connection pooling?
 Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.


9)What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
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.
10) What’s the difference between an interface and abstract class?
In an interface class, all methods are abstract - there is no implementation.  In an abstract class some methods can be concrete.  In an interface class, no accessibility modifiers are allowed.  An abstract class may have accessibility modifiers




ASP.NET:-

1)How can we check if all the validation control are valid and proper?

Using the Page.IsValid () property you can check whether all the validation are done.

2)If client side validation is enabled in your Web page, does that mean server side code is not run.
When client side validation is enabled server emit’s JavaScript code for the custom validators. However, note that does not mean that server side checks on custom validators do not execute. It does this redundant check two times, as some of the validators do not support client side scripting.

3)How to disable client side script in validators?
Set ‘EnableClientScript’ to false.

4)How can we kill a user session?
Session abandon

5)Explain the differences between Server-side and Client-side code?

Server side code is executed at the server side on IIS in ASP.NET framework, while client side code is executed on the browser.

6)How do I sign out in forms authentication?
FormsAuthentication.Signout ()

7)How can we force all the validation control to run?
Page.Validate


What is the use of command objects?

In order to execute Sql commands and stored procedures we
need command objects

What are the two fundamental objects in ADO.NET?
DataSet and DataReader are the tow funadamental object in
ADO.NET

What is Event Bubbling

Server Controls like DataGrid, DataGridView and DataList have other controls inside them. Example The DataGridView can have a TextBox or a button inside it. These Child Controls cannot raise events by themselves, but they pass the event to the parent control (DataGridView), which is passed to the page as "ItemCommand" event. This process is known as EventBubling.

C# General Questions

C# General Questions

   1. Does C# support multiple-inheritance?
      No.
      
   2. Who is a protected class-level variable available to?
      It is available to any sub-class (a class inheriting this class).
      
   3. Are private class-level variables inherited?
      Yes, but they are not accessible.  Although they are not visible or accessible via the class interface, they are inherited.
      
   4. Describe the accessibility modifier “protected internal”.
      It is available to classes that are within the same assembly and derived from the specified base class.
      
   5. What’s the top .NET class that everything is derived from?
      System.Object.

   6)How is the DLL Hell problem solved in .NET?
     Assembly versioning allows the application to specify not only the library it needs to      run (which was available under Win32), but also the version of the assembly.

   7) Is it possible to debug java-script in .NET IDE? If yes, how?
       Yes, simply write "debugger" statement at the point where the breakpoint needs to be        set within the javascript code and also enable javascript debugging in the browser       property settings.

Interview Question

1)which statement is running fastly ie insert or delete?
Its definitely Delete.Becuase When Delete operation is being performed then Oracle
doesnot actualy permanently remove the data from data block
but rather marks that particular data block as unusable.
Whereas when concerned to Insert Oracle needs to insert the
new values into Datablocks.

2)Whats the main difference between Subquery and a Join?
Majorly subqueries  run independently and result of the
subquery used in the outer query(other than corelated subquery).
And in case of join a query only give the result when the
joining condition gets satisfied.


3)what is the difference between first normal form & second
normal form?
First Normal Form:
1.it doesnt contain the duplicate rows and null values.
2.those values can be moved into new table.
second normal form:
1.each columns are completely depend upon key

4)What does COMMIT do ?
Commit is a TCL  command which is  used to make  database
transaction parmanent.The data is commited but it can't be rollbacked.

5)difference between oracle8i and oracle9i?
merge is a command which is used to both insert and delete.
timestamp datatype is introduced.
max no of columns in 8i is 256 where as in 9i we can have
999.
on delete set null supports only in 9i.
by using this, when we delete the parent record the child
records are replaced with null values

6)What is the difference between a procedure and a function ?
Functions return a single variable by value whereas procedures do not return any variable by value.Rather they return multiple variables by passing variables by reference through their OUT parameter.

7)What is the advantage of a stored procedure over a database trigger ?
We have control over the firing of a stored procedure but we have no control over the firing of a trigger.
8)What are cascading triggers? What is the maximum no of cascading triggers at a time?
When a statement in a trigger body causes another trigger to be fired, the triggers are said to be cascading.Max = 32.
9)What are the various types of queries ?
The types of queries are:
Normal Queries
Sub Queries
Co-related queries
Nested queries
Compound queries
10)What is a transaction ?
A transaction is a set of SQL statements between any two COMMIT and ROLLBACK statements.
11)What is PL/SQL?
PL/SQL is Oracle's Procedural Language extension to SQL.The language includes object oriented programming techniques such as encapsulation, function overloading, information hiding (all but inheritance), and so, brings state-of-the-art programming to the Oracle database server and a variety of Oracle tools.

What is the difference WCF and Web services?

What are the major differences between services and Web services? OR What is the difference WCF and Web services?

Web services can only be invoked by HTTP. While Service or a WCF component can be invoked by any protocol and any transport type. Second web services are not flexible. However, Services are flexible. If you make a new version of the service, then you need to just expose a new end. Therefore, services are agile and that is a very practical approach looking at the current business trends.

Loading all the tables from the DB(sql server 2005)

Sub BindData()
Dim strConn As String
strConn = "USER=xxxx;PASSWORD=yyyyy;SERVER=zzz;DATABASE=Emp"
Dim MySQL As String = "Select Column_Name From Information_Schema.Columns Where Table_name ='TableName'"
Dim MyConn As New SqlClient.SqlConnection(strConn)
Dim ds As DataSet = New DataSet()
Dim Cmd As New SqlClient.SqlDataAdapter(MySQL, MyConn)
Cmd.Fill(ds, "Emptbl")
Dim dt As New DataTable
dt = ds.Tables(0)
DropDownList1.DataSource = dt
DropDownList1.DataTextField = dt.Columns("Column_Name").ToString
DropDownList1.DataValueField = dt.Columns("Column_Name").ToString
DropDownList1.DataBind()
End Sub

Multiline property in listbox

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:ListBox ID="ListBox1" runat="server" Rows="4">
<asp:ListItem title="Tooltip1">ListItem1</asp:ListItem>
<asp:ListItem title="Tooltip2">ListItem2</asp:ListItem>
</asp:ListBox>

</div>
</form>
</body>
</html>

Explain about joins in sql

SQL Join:-
Sql Join is used to retrieve data from one or more tables joined by common fields. The most common field is Primarykey from one table and foreign key in another table.
EX:-
Select A.Empno, A.Empname, B.Salary, B. Department from Emp1 A, Emp2 B
Where A.Empno=B.Empno
There are two types of joins in SQL
1) Inner joins-Inner join select rows from both tables. Usually join condition is equality of two columns one from table A and other from table B
Syntax
SELECT
FROM
[INNER] JOIN
ON
2) Outer joins
The outer joins have two subtypes
i) Left outer join
II) right outer join
Outer join extends the functionality of inner join. It returns following rows:
The same rows as inner join i.e,. rows from both tables, which matches join condition and
Rows from one or both tables, which do not match join condition along with NULL values in place of other table's columns.
Outer join syntax is as follows: -
SELECT column list
FROM left joined table
LEFT|RIGHT|FULL [OUTER] JOIN
ON join condition
Cross Join:-
Cross join is used to return all records where each row from first table is combined with each row in second table.
Cross join is also called as Cartesian Product join.
Sql Cross Join Syntax:-
Select * FROM TABLE 1 CROSS JOIN TABLE 2
OR
Select * FROM TABLE 1, TABLE 2

How to create dynamic radio button events

[code]

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 i As Integer
For i = 0 To 56
Dim rd As New RadioButton
rd.ID = i
rd.Text = i
rd.AutoPostBack = True
rd.GroupName = "RD"
AddHandler rd.CheckedChanged, AddressOf RadioButton1_CheckedChanged



PlaceHolder1.Controls.Add(rd)
Next


End Sub

Protected Sub RadioButton1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

MsgBox("asd")
End Sub
End Class

[/code]

What is cross join

Cross Join:-

Cross join is used to return all records where each row from first table is combined with each row in second table.
cross join is also called as Cartesian Product join.

Sql Cross Join Syntax:-

Select * FROM TABLE 1 CROSS JOIN TABLE 2

OR

Select * FROM TABLE 1, TABLE 2

Dynamiclly change drop down items text in bold

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 ddl As New DropDownList
ddl.Items.Add("--Select--")
ddl.Items.Add("Ultimate")
ddl.Items.Add("Rengan")
ddl.Items.Add("Rengan1")
ddl.Items.Add("Rengan2")
ddl.Items.Add("Rengan4")
ddl.AutoPostBack = True
ddl.EnableViewState = True

AddHandler ddl.SelectedIndexChanged, AddressOf DropDownList1_SelectedIndexChanged
PlaceHolder1.Controls.Add(ddl)
Dim i As Integer
For i = 0 To ddl.Items.Count - 1
If i < 3 Then
ddl.Items(i).Attributes.Add("style", "font-weight:bold")
Else
'ddl.Items(i).Attributes.Add("style", "font-weight:italic")
End If
Next

End Sub

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

MsgBox("asd")

End Sub
End Class

TextBox Empty validation using Javascript

hi,
[code]
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Button1.Attributes.Add("onclick", "TextboxEmptyValidation();")
End Sub
[/code]
[code]
<script type ="text/javascript" >
function TextboxEmptyValidation()
{
var empty=document.getElementById("Text1").value;
if (empty=="")
{
alert("Textbox is Empty");
}
}
[/code]
[code]
<asp:Button ID="Button1" runat="server" Text="Button" />
[/code]

How to fill a combobox in vb.net using database

Dim strConn As String
strConn = "USER='" & TextBox1.Text & "';PASSWORD='" & TextBox2.Text & "';SERVER='" & ComboBox1.SelectedItem.ToString & "';"
Dim MySQL As String = "sp_databases"
Dim MyConn As New SqlClient.SqlConnection(strConn)
Dim ds As DataSet = New DataSet()
Dim Cmd As New SqlClient.SqlDataAdapter(MySQL, MyConn)
Cmd.Fill(ds, "Emptbl")
Dim dt As New DataTable
dt = ds.Tables("Emptbl")
ComboBox2.DataSource = dt
ComboBox2.DisplayMember = dt.Columns(0).ToString
ComboBox2.ValueMember = dt.Columns(0).ToString

TextBox to enter only Date

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function checkdate(input)
{
var validformat=/^\d{2}\/\d{2}\/\d{4}$/
var returnval=false
if (!validformat.test(input.value))
alert("Please enter valid date")
else
{ //Detailed check for valid date ranges
var monthfield=input.value.split("/")[0]
var dayfield=input.value.split("/")[1]
var yearfield=input.value.split("/")[2]
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
else
returnval=true
}
if (returnval==false) input.select()
return returnval
}

</script>
</head>
<body>
<form onSubmit="return checkdate(this.mydate)">
<input type="text" name="mydate" />
<b>Date Format:</b> mm/dd/yyyy<br />
<input type="submit" value="submit" />
</form>
</body>
</html>

What is candidate key

candidate Key [Primary Key] is a key which maintains the Row Unique.
it Can be defined based on the entity.
composite Key can be either Primay or Unique Key.
More then One Key columns are said to be composite keys.
Candidate Key(Primary Key) is a column in a table which has the
ability to become a primary key.But a primary key does not necessarily have to be the target of any foreign keys.
The candidate key must be unique within its domain.

Site map Control with Example

SiteMap

Create menu using SiteMap

1)Right click the Project Name
2)Choose The New Item
3)Choose "SiteMap" From Add NewItem window

Web.DotNetSiteMap Its look like,
[code]
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="" title="" description="">
<siteMapNode url="" title="" description="" />
<siteMapNode url="" title="" description="" />
</siteMapNode>
</siteMap>
[/code]

In Form
1)Add the Menu controls to Form
2)Go to the Property window
3)choose New Datasource from Datasource ID of Menu control
4)DataSource Configuration Wizard window will display
5)then coose the "Site Map"

Example :-

web.SiteMap:-
[code]
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="File" title="File" description="File">
<siteMapNode url="Default2.aspx" title="SecondPage" description="ThirdPage" />
<siteMapNode url="Default3.aspx" title="ThirdPage" description="ThirdPage" />
</siteMapNode>
</siteMap>
[code]
Default.aspx:-
[code]
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />


</div>
</form>
</body>
</html>

[/code]

how to check a particular table is exists /not in database

if EXISTS (select * from INFORMATION_SCHEMA.tables where table_name = 'tablename')
Select 'Table found'
ELSE SELECT 'TABLE NOT FOUND'

How many ways can read Excel file in C#.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string path;
path = "C:\\";
DataTable grdDataSet = new DataTable();
grdDataSet= GetDataTableFromExcel(path);
GridView1.DataSource = grdDataSet;
GridView1.DataBind();
}
public static DataTable GetDataTableFromExcel(string SourceFilePath)
{
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + SourceFilePath + ";" +
"Extended Properties=\"Text;HDR=YES;\"";

using (OleDbConnection cn = new OleDbConnection(ConnectionString))
{
cn.Open();

DataTable dbSchema = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dbSchema == null || dbSchema.Rows.Count < 1)
{
throw new Exception("Error: Could not determine the name of the first worksheet.");
}

string WorkSheetName = dbSchema.Rows[0]["TABLE_NAME"].ToString();
// string WorkSheetName = "ExcelData.csv";
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + WorkSheetName + "]", cn);
DataTable dt = new DataTable(WorkSheetName);
da.Fill(dt);
return dt;
}
}

}

How to hide/display a label using javascript

hi,
check this code
[code]
<%@ 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">
<script type="text/javascript">

function expand(thistag, tag) {
styleObj=document.getElementById(thistag).style;
if (styleObj.display=='none')
{
styleObj.display='';
tag.innerHTML = "Click here to hide";
}
else {
styleObj.display='none';
tag.innerHTML = "Click here to show";
}
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" onclick="expand('Label1', this);" Text="click me"></asp:Label>
</div>
</form>
</body>
</html>

[/code]

How to get the id of textbox dynamically?

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 x As String
x = TextBox1.ID
MsgBox(x)
End Sub
End Class

Passing values from one aspx page to another aspx page in asp.net

Querystring:

Query string is used to Pass the values or information form one page to another page.
Syntax
Request.QueryString(variable)[(index)|.Count]
Parameters
variable :-
Specifies the name of the variable in the http query string to retrieve.
index :-
An optional parameter that enables you to retrieve one of multiple values for variable. It can be any integer value in the range 1 to Request.QueryString(variable).Count.

For exapmle:-
In page 1:
Drag and drop the one textbox and button control
In page 2:
Drag and drop the one textbox control from tool box and place it on form.
In page one:-
[CODE]
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'bind the textbox values to querystring
Response.Redirect("Default2.aspx?Textboxvalue=" & TextBox1.Text)

End Sub
End Class
[/CODE]
In page two:-
[CODE]
Partial Class Default2
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Get the values from Query string
TextBox1.Text = Request.QueryString("Textboxvalue")
End Sub
End Class

[/CODE]

Difference between sub & function in vb.net

Sub is a method.its does not return any value
Function is method and it will return any value

Primary key and unique key

Primary key and unique are Entity integrity constraints.unique key can be null but primariy key cant be null.
primariy key can be refrenced to other table as FK.We can declare only one primary key in a table but a table can have multiple unique key.

What is constructor? give an example

A constructor is a special method for initializing a new instance of a class
The constructor method is same name as the class name.A class have more than one constructor.
In this case each constructor have same name but different Parameters.

Example:-


public class A
{
public int x = 0
public int y = 0
public int radius = 0

public A(int x, int y, int radius)
{
this.x = x;
this.y = y;
this.radius = radius;
}
}



1)Copy Construtor
2)paramiterised constructor
3)Dummy constructor
4)Dynamic constructor

How to remove space for a string?

[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)
{
Label2.Text = "Dynamic Remove Space";
Label1.Text = "Dynamic Remove Space";
Label1.Text=Label1.Text.Replace(" ","");
}
}

[/code]

Difference between vb and vb.net

1)VB6 does not support inheritance but VB .NET does
2)VB6 does not support polymorphism but VB .NET does

3) vb is opps based, But VB.Net is Completely supported for oops
4) In dotnet we can develop console applications, web applications, mobile apps, smart device apps,
But this was not possible in vb.
5) Lot of Advanced controls available in vb.net

6) in vb, only recordset concepts ( connection methods) are available, ex. DAO, ADO, RDO methods.
But in dotnet ado.net(disconnected Database) method is also availble.
7) Cross language integration, Cross language Debugging and cross langauge inheritance is also possible in vb.net.

How to open a notepad with maximized size using c#.net (windows application)

You can use this code both windows and web application
System.Diagnostics.ProcessStartInfo myProc = new System.Diagnostics.ProcessStartInfo();
myProc.FileName = "Notepad.exe";
myProc.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
System.Diagnostics.Process.Start(myProc);

Example for Windows Application:-

[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

System.Diagnostics.ProcessStartInfo myProc = new System.Diagnostics.ProcessStartInfo();
myProc.FileName = "Notepad.exe";
myProc.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
System.Diagnostics.Process.Start(myProc);

}
}
}

[/code]

How to count or find folder in a drive?

[code]
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim numberOfFiles As Integer
Dim path As String = "c:\rengan"
numberOfFiles = System.IO.Directory.GetFiles(path).Length
MsgBox(numberOfFiles)
End If
End Sub
[/code]

Add row dynamically in gridview

[code]
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim dtrow As DataRow
Dim dstDataSet As DataSet
Public Shared Function GetFieldType(ByVal FieldType As String) As System.Type
Select Case FieldType
Case "int"
Return Type.GetType("System.Int32")
Case "varchar"
Return Type.GetType("System.String")
Case "datetime"
Return Type.GetType("System.DateTime")
Case "float"
Return Type.GetType("System.Double")
End Select
Return Type.GetType("System.Object")
End Function

Public Shared Function DefineDataset(ByVal Field() As String, ByVal FieldType() As String, ByVal PrimaryKey As String) As DataSet
Dim dstDataset As New DataSet
Dim dtTable As New DataTable
Dim i As Integer
For i = 0 To FieldType.Length - 1
dtTable.Columns.Add(New DataColumn(Field(i), GetFieldType(FieldType(i))))
If Field(i) = PrimaryKey Then
dtTable.Constraints.Add("c" & i, dtTable.Columns(i), True)
End If
Next
dstDataset.Tables.Add(dtTable)
Return (dstDataset)
End Function
Public Property GridBindDataSet() As DataSet
Get
If Not (ViewState("GridDataset") Is Nothing) Then
dstDataSet = CType(ViewState("GridDataset"), DataSet)
End If
If dstDataSet Is Nothing Then
dstDataSet = DefineDataset(New String() {"EmpID", "EmpName"}, New String() {"varchar", "varchar"}, "")
ViewState.Add("GridDataset", dstDataSet)
End If
Return dstDataSet
End Get

Set(ByVal value As DataSet)
dstDataSet = value
If Not (ViewState("GridDataset") Is Nothing) Then
ViewState("GridDataset") = dstDataSet
Else
ViewState.Add("GridDataset", dstDataSet)
End If
End Set
End Property
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim drwRow As DataRow = GridBindDataSet.Tables(0).NewRow()
drwRow("EmpID") = ""
drwRow("EmpName") = ""
GridBindDataSet.Tables(0).Rows.Add(drwRow)
GridView1.DataSource = GridBindDataSet
GridView1.DataBind()
End If
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim drwRow As DataRow = GridBindDataSet.Tables(0).NewRow()
drwRow("EmpID") = ""
drwRow("EmpName") = ""
GridBindDataSet.Tables(0).Rows.Add(drwRow)
GridView1.DataSource = GridBindDataSet
GridView1.DataBind()
End Sub
End Class

[/code]

How to create gridview programaticlly

Just create the Datatable and bind it to Gridview control.

Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim dtrow As DataRow
Dim dtNewTable As New DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dtcol, dtcol1 As New DataColumn
dtcol.DataType = System.Type.GetType("System.String")
dtcol.ColumnName = "Emp ID"
dtNewTable.Columns.Add(dtcol)
dtcol1.DataType = System.Type.GetType("System.String")
dtcol1.ColumnName = "Emp Name"
dtNewTable.Columns.Add(dtcol1)
Dim i As Integer
For i = 0 To 4
dtrow = dtNewTable.NewRow()
dtrow("Emp ID") = ""
dtrow("Emp Name") = ""
dtNewTable.Rows.Add(dtrow)
Next i
GridView1.DataSource = dtNewTable
GridView1.DataBind()
End Sub
End Class

How to chane the color of Label?

User Name:
Password :

I want to change the color for the label User Name and Password. Bydefault it is black. How to chnage these label colors?

Ans:-

<%@ 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>
<style type="text/css">
.style1
{
width: 100%;
border-style: solid;
border-width: 1px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellspacing="1" class="style1">
<tr>
<td style="color:Red">
UserName</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="color:Blue">
PassWord</td>
<td >
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

how to fetch final digit in this label Ex:123456789 i need to get the value "9" in a string using vb.net

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 sst As String
sst = "123456789"
Dim ssttt As String

ssttt = sst.Substring(sst.Length - 1)

End Sub
End Class

How can I disable IE/Firefox to remember password for my website?

<%@ 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:TextBox ID="TextBox1" autocomplete="off" runat="server" TextMode="Password"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

</div>

</form>
</body>
</html>

[/code]

How to get the current url of the page

string CurrentURL = System.Web.HttpContext.Current.Request.Url;

How To Dynamically Change Page Title?

protected void Page_Load(object sender, EventArgs e)
{

Page.Title = "Loading";
}
protected void Button1_Click(object sender, EventArgs e)
{
Page.Title = "super";
}

How to get n th highest value in Sql Server table?

SELECT TOP 1 fieldname FROM (SELECT TOP 9 fieldname FROM tablename ORDER BY fieldname desc) AS E ORDER BY fieldname asc

Gridview with Paging using C#

HI friend,
check the below example

[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)
{
if(!Page.IsPostBack)
{
Gridbind();
}

}
public void Gridbind()
{

DataSet ds = new DataSet();

string str;

str = "USER=as;PASSWORD=asd;SERVER=servername;DATABASE=asd";
SqlConnection con=new SqlConnection(str);
SqlDataAdapter da = new SqlDataAdapter("select * from Tablename", con);
da.Fill(ds, "Employee");
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Gridbind();
}
}





<%@ 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:GridView ID="GridView1" AllowPaging="true" runat="server"
onpageindexchanging="GridView1_PageIndexChanging" PageSize="2">
</asp:GridView>
</div>
</form>
</body>
</html>

[/code]

How to Call JavaScript Function on PageLoad Event?

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





Untitled Page







[/code]

Which two properties are on every validation control?

1)ErrorMessage
2)Control to Validate
3)Set Focus On Error

How to open word file on clicking image button

Just drag and drop the iframe in your page or else just paste the below code


In page load event just
myPDF.Attributes.Add("src", filepath);

How to put confirmation box at gridview hyperlink column?

In Gridview row databound just assign your javascript function to link button.

Dim vlblCtrl As LinkButton = (CType(e.Row.FindControl("Lnk"), LinkButton))
vlblCtrl.Attributes.Add("onclick", "call your javascript function")

Password textbox is being blank on seleted index changed of dropdown


HI friend,
check this code

[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)
    {
        myBody.Attributes.Add("onload", "document.getElementById('txtPassword').value = '" + txtPassword.Text.ToString() + "'");

           


    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
       
    }
}


<%@ 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 id="myBody" runat="server" >
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtPassword" TextMode="Password"  runat="server"></asp:TextBox>
        <asp:DropDownList ID="DropDownList1" AutoPostBack="true"  runat="server"
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem>Abc</asp:ListItem>
            <asp:ListItem>XYZ</asp:ListItem>
            <asp:ListItem>Nothing</asp:ListItem>
        </asp:DropDownList>
    </div>
    </form>
</body>
</html>

[/code]

Gridview Binding from Two tables

CHECK THE BELOW CODE

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

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        BindData()

    End Sub
    Sub BindData()
        Dim strConn As String
        strConn = "USER=ASDF;PASSWORD=ASDF;SERVER=ASD;DATABASE=ASDF"
        Dim MySQL As String = "select A.Emp_Name,B.salary from emp A,salary B where A.emp_id=B.empid"
        Dim MyConn As New SqlClient.SqlConnection(strConn)
        Dim ds As DataSet = New DataSet()
        Dim Cmd As New SqlClient.SqlDataAdapter(MySQL, MyConn)
        Cmd.Fill(ds, "Emptbl")
        Dim dt As New DataTable
        dt = ds.Tables(0)
        GridView1.DataSource = dt
        GridView1.DataBind()
    End Sub

End Class

[/CODE]

Difference Between XML and HTML

 XML and HTML :-
XML stands for--->Extensible Markup Language.
HTML stands for--->Hypertext Markup Language.
In HTML we cant write own tags but in XML we can write own tags.
XML is dyanmic but HTML is Static.HTML is presentation language where as xml is not presentation Language.
XML is used to transfer data between application and databases.XML is Case Sensitive.
But HTML is not case Sensitive.

Difference Between VB.Net and C#

1)Vb.Net having supports optional parameters but C# doesnt.
2)C# doesnt have equivalent of vb with/Endwith statements.
3)Vb.Net not case sensitive
4)C# is case sensitive
5)There is no Pointer Type variables in vb.net
6)There is no xml document available in vb.net but C# have
7)Variable declaration in vb.net like
Dim x as string
8)variable declaration in C# like
string x ;

How to take last inserted Record in SQL Server?

Take the below query to take last inserted Record.

select top 1 * from tablename order by fieldname desc

Indexes in SQL Server

Indexes:-
Its used to change the order of data or to add metadata for improving the performance of queries.
There are two types of indexes
1)Clustered indexes
2)Non-Clustered indexes


Clustered Indexes
 1)Physically stored in order (Ascending or descending)
2) only one per table
3)When a primary key is created a clustered index is automatically created as well

4) If the table is under heavy data modifications or the primary key is used for searches, a clustered index on the primary key is recommended.
5) Columns with values that will not change at all or very seldom, are the best choices.

Non-Clustered indexes
1)upto 249 non clustered indexes are possible per table
2)The clustered index keys are used for searching therefore clustered index keys should be chosen with a minimal length.
3) Covered queries (all the columns used for joining, sorting or filtering are indexed) should be non-clustered.
4)Foreign keys should be non-clustered.
If the table is under heavy data retrieval from fields other than the primary key,
one clustered index and/or one or more non-clustered indexes should be created for the column(s) used to retrieve the data

How to trace ip address through javascript?

I think its not possible.

How to delete cookie using javascript?

   The del_cookie() function is used to delete the cookie in javascript
Example
function del_cookie(name)
{
document.cookie = name +
'=; expires=Thu, 01-Apr-70 00:00:01 GMT;';
}

How to convert String to Float and Float to String?

Converting String to Float

if you want to convert a value from string to float ,you have to use the function
parseFloat().

Example:-
parseFloat("4.222");      4.222
parseFloat("5bbb");     5
parseFloat("6e2");     600
parseFloat("bbb");     NaN (means "Not a Number")


Converting Integer/Float to String

Integer (int) or float value can be converted to string by using the function or method toString().

Example:-

var a = 3.22;
a.toString();     "3.22"
var a = 5;
a.toString();     5

Example 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>


<body>
<script type="text/javascript" >
var a = 24;
var b = 666;
var c = a.toString()+b;
document.write(" to String function "+c);
</script>
    <form id="form1" runat="server">
    <div>
   
    </div>
    </form>
</body>
</html>





Result:-
to String function -> 24666

What is CTS,CLS and CLR?

1.What is Common Type System (CTS)?
   CTS defines all of the basic types that can be used in the .NET Framework and the operations performed on those type.
All this time we have been talking about language interoperability, and .NET Class Framework. None of this is possible without all the language sharing the same data types. What this means is that an int should mean the same in VB, VC++, C# and all other .NET compliant languages. This is achieved through introduction of Common Type System (CTS).
2.What is Common Language Specification (CLS)? 
CLS is the collection of the rules and constraints that every language (that seeks to achieve .NET compatibility) must follow. It is a subsection of CTS and it specifies how it shares and extends one another libraries.
3.What is Common Language Runtime (CLR)? 
CLR is .NET equivalent of Java Virtual Machine (JVM). It is the runtime that converts a MSIL code into the host machine language code, which is then executed appropriately. The CLR is the execution engine for .NET Framework applications. It provides a number of services, including: 

- Code management (loading and execution)
- Application memory isolation
- Verification of type safety
- Conversion of IL to native code.
- Access to metadata (enhanced type information)
- Managing memory for managed objects
- Enforcement of code access security
- Exception handling, including cross-language exceptions
- Interoperation between managed code, COM objects, and pre-existing DLL's (unmanaged code and data)
- Automation of object layout
- Support for developer services (profiling, debugging, and so on).

Basic Interview Question

1)Can you run an application without web.confige file?
Yes
2)What is default time of expire session?
20 minute 
3)Which namespace is used to get assembly details?
System.Assembly

4)What will be the output of Following code String a=”Hello”; String b=”World” String c= a+b Response.Write ( “C “);
C
5)If an Aspx page is requested from the web server, the out put will be rendered to browser in following format.
HTML

6)Which Method of Data Adapter is used to Populate the DataSet?
Fill
7)How Many Machine.Config Files are possible ?
1
8)Which two properties are same on every validation control?
Controltovalidate & Error Message
9)Which Class cannot be Instantiated?
Static class
Sealed Class
10)Where Cookies are stored?
Client Side

How to find last day of previous ,current and next month using sql server?

How to find last day of previous ,current and next month using sql server?

Following Query demonstrates the script to find last day of previous, current and next month.

----Last Day of Previous Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))

OutPut:-
2010-03-31 23:59:59.000
SELECT convert(varchar(10),DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)))
OutPut:-
Mar 31 201


----Last Day of Current Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
OutPut:-
2010-04-30 23:59:59.000

SELECT convert(varchar(10),DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)))
OutPut:-
Apr 30 201


----Last Day of Next Month
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))
OutPut:-
2010-05-31 23:59:59.000
SELECT convert(varchar(10),DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0)))
OutPut:-
May 31 201

If you want to find last day of month of any day specified use following Query.
--Last Day of Any Month and Year
DECLARE @dtDate DATETIME
SET @dtDate = '8/18/2003'
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@dtDate)+1,0))

Set a database to read only mode using SQL Server 2005 and 2008?

   In most DBA or Database Administration purpose we need to set a Database to readonly mode.Here i will show you how you can set Database in Read Only mode for Sql server 2005 and  Sql Server 2008.One thing keep in mind that you can not use same sql command for both sql server 2005 and 2008.Thats why here i will show the different ways to manage a Database to Read Only mode.The another important note is you can not make a database read only until you set the Database in single user mode. So first set the database in single user mode.

To bring a database to the single user mode, use the following query:

[code]
ALTER DATABASE  DATABASENAME SET  SINGLE_USER
[/code]

After execute this query your database will change single user mode.if you want to change single user to multiple user means
take below query

[code]
ALTER DATABASE  DATABASENAME SET  MULTI_USER
[/code]

Sql Server 2005:
   [code]
    EXEC sp_dboption "YourDatabaseName", "read only", "True";
[/code]
   After executing the above command then refresh the your database.
You will see that the DataBase now set to Read Only mode like below:

See Attachements:Image 1


Now if anyone try to enter or update a data into the database he will receive the below error:
See Attachements: image 2

 Sql Server 2008:
To make the Database read only in 2008 run the below SQL:

     USE master;
     GO
     ALTER DATABASE databasename
     SET READ_ONLY;
     GO

How to view full image in asp.net?

If you click the sunset image,the image will display with full size in a new window.
In this artilce i will explain how one can display a full or zoom image from sunset image.

[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>
<script type="text/javascript">
function DisplayFullImage(ctrlimg)
{
txtCode = "<HTML><HEAD>"
+ "</HEAD><BODY TOPMARGIN=0 LEFTMARGIN=0 MARGINHEIGHT=0 MARGINWIDTH=0><CENTER>"
+ "<IMG src='" + ctrlimg.src + "' BORDER=0 NAME=FullImage "
+ "onload='window.resizeTo(document.FullImage.width,document.FullImage.height)'>"
+ "</CENTER>"
+ "</BODY></HTML>";
mywindow= window.open ('','image', 'toolbar=0,location=0,menuBar=0,scrollbars=0,resizable=0,width=1,height=1');
mywindow.document.open();
mywindow.document.write(txtCode);
mywindow.document.close();
}

</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Image ID="Image1" BorderColor="black" BorderWidth="1px"
width="200px" height ="200px" runat="server"
ImageUrl = "Sunset.jpg" onclick="DisplayFullImage(this);"/>

</div>

</form>
</body>
</html>


[/code]