Sunday, 31 August 2014

Maximum length of Querystring

Maximum length of Querystring is based on the browser not depend upon the asp.net.
Maximum length of a querystring in IE 4.0 and above is ~2048 characters

IE. 4,5,6,7, - 2,048 characters.
Opera supports - 4050 characters.
Netscape 6 supports - 2000 characters.
Firefox Supports - 6000 characters 


HTML5 Pattern

Name Pattern

1.Alpha-Numeric  -  [a-zA-Z0-9]+
2.Username with 2-20 chars  - ^[a-zA-Z][a-zA-Z0-9-_\.]{1,20}$

Password Pattern

1.Password (UpperCase, LowerCase, Number/SpecialChar and min 8 Chars)

Pattern= (?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$

2.Password (UpperCase, LowerCase and Number)

Pattern = ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$

Phone Pattern

Pattern=[\+]\d{2}[\(]\d{2}[\)]\d{4}[\-]\d{4}

Date Pattern

Pattern= (0[1-9]|1[0-9]|2[0-9]|3[01]).(0[1-9]|1[012]).[0-9]{4}
Format ex:  DD.MM.YYYY

Pattern=[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])
Format ex:  YYYY-MM-DD

Sunday, 24 August 2014

HTML5 for TextBox



<asp:TextBox ID="txtName" runat="server" placeholder="Name" required="a" title="Enter the Name" pattern="[a-zA-Z]+"></asp:TextBox>

when submit the textbox as  empty validation Required

Title is for small alert Message  for the user.
Placeholder is the small Description of the Input which is needed .
Required is  the Required Field Validation
Pattern  Checking for input 

Cursor in SQL

DECLARE @Id int
DECLARE @name varchar(50)
DECLARE cur_emp CURSOR
STATIC FOR SELECT Sno,Name from EmpName
OPEN cur_emp
IF @@CURSOR_ROWS > 0
 BEGIN
 FETCH NEXT FROM cur_emp INTO @Id,@name
 WHILE @@Fetch_status = 0
 BEGIN
 -- select @Id,@name
 PRINT 'ID : '+ convert(varchar(20),@Id)+', Name : '+@name
 FETCH NEXT FROM cur_emp INTO @Id,@name
 END
END
CLOSE cur_emp
DEALLOCATE cur_emp


Output :

ID : 1, Name : Sendhilkumar
ID : 2, Name : ArunKumar
ID : 3, Name : BBBB

Syntax to Declare Cursor
Declare Cursor SQL Comaand is used to define the cursor with many options that impact the scalablity and loading behaviour of the cursor. The basic syntax is given below
  1.  DECLARE cursor_name CURSOR
  2.  [LOCAL | GLOBAL] --define cursor scope
  3.  [FORWARD_ONLY | SCROLL] --define cursor movements (forward/backward)
  4.  [STATIC | KEYSET | DYNAMIC | FAST_FORWARD] --basic type of cursor
  5.  [READ_ONLY | SCROLL_LOCKS | OPTIMISTIC] --define locks
  6.  FOR select_statement --define SQL Select statement
  7.  FOR UPDATE [col1,col2,...coln] --define columns that need to be updated
Syntax to Open Cursor
A Cursor can be opened locally or globally. By default it is opened locally. The basic syntax to open cursor is given below:
  1.  OPEN [GLOBAL] cursor_name --by default it is local
Syntax to Fetch Cursor
Fetch statement provides the many options to retrieve the rows from the cursor. NEXT is the default option. The basic syntax to fetch cursor is given below:
  1.  FETCH [NEXT|PRIOR|FIRST|LAST|ABSOLUTE n|RELATIVE n]
  2. FROM [GLOBAL] cursor_name
  3. INTO @Variable_name[1,2,..n]
Syntax to Close Cursor
Close statement closed the cursor explicitly. The basic syntax to close cursor is given below:
  1.  CLOSE cursor_name --after closing it can be reopen
Syntax to Deallocate Cursor
Deallocate statement delete the cursor definition and free all the system resources associated with the cursor. The basic syntax to close cursor is given below:
  1.  DEALLOCATE cursor_name --after deallocation it can't be reopen


Merging GridView Header Columns Multiple Headers ASP.NET



In Aspx Page
<asp:GridView ID="GridView1" runat="server"  DataSourceID="SqlDataSource1" 
OnRowCreated="GridView1_RowCreated" ShowHeader="False">
<Columns>
<asp:BoundField DataField="DepartMentID" HeaderText="DepartMentID"/>
<asp:BoundField DataField="DepartMent" HeaderText="DepartMent"/>
<asp:BoundField DataField="Name" HeaderText="Name"/>
<asp:BoundField DataField="Location" HeaderText="Location"/>
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [DepartMentID], [DepartMent], [Name], 
              [Location] FROM [Employee]">
</asp:SqlDataSource>


In C#
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            GridView HeaderGrid = (GridView)sender;
            GridViewRow HeaderGridRow = new GridViewRow(0, -1, DataControlRowType.Header, DataControlRowState.Insert);
            TableCell HeaderCell = new TableCell();
            HeaderCell.Text = "Department";
            HeaderCell.ColumnSpan = 2;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "Employee";
            HeaderCell.ColumnSpan = 2;
            HeaderGridRow.Cells.Add(HeaderCell);

            GridView1.Controls[0].Controls.AddAt(0, HeaderGridRow);

   HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
            HeaderCell = new TableCell();
            HeaderCell.Text = "DepartMentID";
            HeaderCell.RowSpan = 1;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "DepartMent";
            HeaderCell.RowSpan = 1;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "Name";
            HeaderCell.RowSpan = 1;
            HeaderGridRow.Cells.Add(HeaderCell);

            HeaderCell = new TableCell();
            HeaderCell.Text = "Location ";
            HeaderCell.RowSpan = 1;
            HeaderGridRow.Cells.Add(HeaderCell);

            GridView1.Controls[0].Controls.AddAt(1, HeaderGridRow);

        }
    }

Saturday, 23 August 2014

CodeBehind And CodeFile

CodeBehind : Needs to be compiled  and compiled binary is placed in the bin folder of the website. You need to do a compile in visual studio before you deploy. Good model when you do not want the source code to be viewable as plain text ... for example when delivering to a customer who you not have obligation to provide code.

CodeFile : You provide the source file with the solution for deployment. ASP.NET 2.0 runtime compiles the code when needed. The compiled files are at Microsoft.NET[.NET version]\Temporary ASP.NET Files.

Delegates

Suppose if you have multiple methods with same signature (return type & number of parameters) and want to call all the methods with single object then we can go for delegates.
Delegates are two types
      -   Single Cast Delegates
      -  Multi Cast Delegates

Example:
public delegate int DelegatSample(int a,int b);
public class Sampleclass
{
public int Add(int x, int y)
{
return x + y;
}
public int Sub(int x, int y)
{
return x - y;
}
}
class Program
{
static void Main(string[] args)
{
Sampleclass sc=new Sampleclass();
DelegatSample delgate1 = sc.Add;
int i = delgate1(10, 20);
Console.WriteLine(i);
DelegatSample delgate2 = sc.Sub;
int j = delgate2(20, 10);
Console.WriteLine(j);
}
}


Assembly

“An assembly may be Public or Private. A public assembly is also called a Shared Assembly.” 

1.The .NET assembly is the standard for components developed with the Microsoft.NET. 
2.Dot NET assemblies may or may not be executable, i.e., they might exist as the executable (.exe) file or dynamic link library (DLL) file.
3.All the .NET assemblies contain the definition of types, versioning information for the type, meta-data, and manifest. The designers of .NET have worked a lot on the component (assembly) resolution.
Advantages of Assemblies
1.        In the case of DLLs if a DLL has to be shared with some other application, it has to be registered in that particular machine. But, In the case of Asp.net assemblies there is no such type of registration required. Here we just need to do is to copy the assembly and put in the bin directory of the application that is going to use it.
2.        If we need to share a particular assembly with any other applications. we can do so by placing the assembly in the Global Assembly Cache (GAC). But before we going to do it we need to give a strong name to that assembly.Strong name is similar to GUID(It is supposed to be unique in space and time) in COM, components.Strong Name is only needed when we need to deploy assembly in Global Assembly Cache (GAC).Strong Names helps GAC to differentiate between two versions.Strong names use public key cryptography (PKC) to ensure that no one can spoof it.PKC use public key and private key concept.
3.        Another advantage of using ASP.Net assemblies is the ability to read the contents of an assembly. Each assembly has a manifest that has details about the assembly itself.
4.        The System.Reflection namespace has classes like Assembly which can be used to get the details of the assembly and with that it is also possible to load an assembly dynamically at runtime.

There are three types of assemblies in .NET
Private Assemblies
Public/Shared Assemblies.
Satellite Assembly

Private Assemblies

Is the assembly which is used by application only, normally it resides in your application folder directory.

There is no version constraint in private assembly.

If an assembly is copied in to the respective application in which we would like to use is known as local assembly. if any changes made to the copy that will not reflect the copies in other applications.

 Public Assemblies

It resides in GAC, so that anyone can use this assembly. Public assemblies are always share the common.
It has version constraint.
This public assembly is stored inside the global assembly cache or GAC.GAC contains a collection of shared assemblies.
If an assembly is copied into the global place and reference is used from all other applications then this is called public or global assembly..if we want to copy assembly in global place we have to create strong name by using sn.exe.

Satellite Assembly
Satellite assemblies are used to build multi-linguistic applications. Application which has built in supportive of more than one human readable language is known as multi-linguistic applications.
Satellite Assemblies doesn’t contain any Data
Satellite assembly is containing cultural information.
Satellite assembly mainly used for to display information based on the Cultural setting of browser or region.

Suppose you developed your application in an English (en-US) locale. Now, your application has multilingual support. When you deploy your code in different location, for example in India, you want to show text, label messages in the national language (local language) which is other than English.

Satellite assemblies give this flexibility. You create any simple text file with translated strings, create resources, and put them into the bin\debug folder. That's it. The next time, your code will read the CurrentCulture property of the current thread and accordingly load the appropriate resource.






Int32 and Int

Int is a data type keyword defined by the language, C#.
Int32 is a data type defined by the .NET Common Type System (CTS).

  • Int16 : 2 bytes
  • Int32 and Int: 4 bytes
  • Int64 : 8 bytes


Partial class

partial class splits the definition of a class over two or more source files. You can create a class definition in multiple files but it will be compiled as one class.

Interface Vs Abstract Class

Interface
Abstract Class
Interface support multiple inheritance
Abstract class does not support multiple inheritance
Interface does'n Contains Data Member
Abstract class contains Data Member
An interface Contains only incomplete member (signature of member)
An abstract class Contains both incomplete (abstract) and complete member
Member of interface can not be Static
Only Complete Member of abstract class can be Static
An interface cannot have access modifiers by default everything is assumed as public
An abstract class can contain access modifiers for the subs, functions, properties

Arrays Vs ArrayLists

                             Arrays
                                 ArrayLists
These are strong type collection and allow to store fixed length
                Array Lists are not strong type collection and size will increase or decrease dynamically

In arrays we can store only one datatype either int, string, char etc…

In arraylist we can store all the datatype values
Arrays belong to System.Array namespace
string[] arr=new string[2];
arr[0] = "welcome";
arr[1] = "Aspdotnet-Sendhilkumar";

Arraylist belongs to System.Collection namespaces
ArrayList strarr = new ArrayList();
strarr.Add("welcome"); // Add string values
strarr.Add(10);   // Add integer values
strarr.Add(10.05); // Add float values

Overloading Vs Overriding

Overloading is defining functions that have similar signatures, yet have different parameters. 

Overriding is only pertinent to derived classes, where the parent class has defined a method and the derived class wishes to override that function.

Overriding
Overloading
Methods name and signatures must be same.
Having same method name with different
Signatures.
Overriding is the concept of runtime polymorphism
Overloading is the concept of compile time polymorphism
When a function of base class is re-defined in the derived class called as Overriding
Two functions having same name and return type, but with different type and/or number of arguments is called as Overloading
It needs inheritance.
It doesn't need inheritance.
Method should have same data type.
Method can have different data types
Method should be public.
Method can be different access specifies
Overriding

public class MyBaseClass
{
    public virtual void MyMethod()
    {
        Console.Write("My BaseClass Method");

    }
}
public class MyDerivedClass : MyBaseClass
{
    public override void MyMethod()
    {
        Console.Write("My DerivedClass Method");

    }
}

Overloading 

int add(int a, int b)
int add(float a , float b)

Types of cookies

Session cookies - these are temporary and are erased when you close your browser at the end of your surfing session. The next time you visit that particular site it will not recognise you and will treat you as a completely new visitor as there is nothing in your browser to let the site know that you have visited before (more on session cookies).


Persistent cookies - these remain on your hard drive until you erase them or they expire. How long a cookie remains on your browser depends on how long the visited website has programmed the cookie to last (more on persistent cookies).

Saturday, 9 August 2014

ModalPopupExtender Ajax Tool

In Aspx Page

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Show Popup" />

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
 
    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
        PopupControlID="Panel1" TargetControlID="Button1">
    </asp:ModalPopupExtender>
    <asp:Panel ID="Panel1" runat="server">
    welcome
        <asp:Button ID="btncancel" runat="server" Text="Button"
            onclick="btncancel_Click" />
    </asp:Panel>

In C#
    protected void Button1_Click(object sender, EventArgs e)
    {
        ModalPopupExtender1.Show();
    }
    protected void btncancel_Click(object sender, EventArgs e)
    {
        ModalPopupExtender1.Hide();
    }

Static Classes

Static methods are used when you will need to access a method from many different classes or forms, you wouldn't want to create an object every time you needed that method. and you certainly wouldn't want to retype or copy and paste the same method into every class you needed it in.

Types of Access Modifiers

Public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
Private
The type or member can only be accessed by code in the same class or struct.
Protected
The type or member can only be accessed by code in the same class or struct, or in a derived class.
Internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.
Protected Internal

The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly. 

Boxing and UnBoxing concepts in .net

Boxing
Unboxing
Definition:
Boxing is the process of converting a value type to the reference type.
Unboxing is the process of converting
a reference type to value type
.
Type of Conversion:
Implicit Conversion
Explicit Conversion
Example:
inti = 221;
object obj = i; //boxing
object obj = 213;
i = (int)obj ; // unboxing

class SenTest
{
               static void Main() {
                               int i = 1;
                               object o = i;                           // boxing
                               int j = (int) o;         // unboxing
               }
}