Tuesday, 29 September 2015

VALIDATION CONTROLS IN ASP .NET

VALIDATION CONTROLS IN ASP .NET

Validation server controls are the only type of ASP.NET server controls that also generate client-side script. All the other controls work with the idea of making postbacks to the server (a request to the server to get a response).


Types of Validation
1-Client Side Validation
2-Server Side Validation

There are Six Type of Validation Controls
1-RequiredField Validator :- Make an input controls a required field.

2-Compare Validator :- Compare the value of one input control to the value of another input control or to a fixed value .

3-Range Validator :-Checks that the user enters a value that falls between two values.

4-Regular-expression Validator :- Ensures that the value of an input control matches a specified pattern.

5-Custom Validator :- Allow you to write a method to handle the validation of the value entered.

6-Validation Summary :- Displays a report of all validation errors occurred in a web page.



Monday, 28 September 2015

Boxing and Unboxing in C# .Net

Boxing and Unboxing in C# .Net

Boxing :- Conversion of Value type into Object data type is Known as Boxing.
It is automatically called by Compiler.
e.g :- Image -1









Unboxing :- Conversion of Object type into Value data type is Known as Unboxing.

NOTE :- Unboxing the execution of it then there is always need of Type Casting Method.

e.g:- Image-2



Saturday, 26 September 2015

ASP .NET STATE MANAGEMENT

ASP .NET STATE MANAGEMENT

INTRODUCTION

State management is the process by which you maintain state and page information over multiple requests for the same or different pages. 





















TYPES OF STATE MANAGEMENT

- Client-side state management
- Server-side state management 

CLIENT SIDE STATE MANAGEMENT

ASP.NET provides several techniques for storing state information on the client. 
This maintains information on the client's machine using Cookies, View State, and Query Strings.

1-View State :-Each page and each control on the page has View State property. This property allows automatic retention of page and controls state between each trip to server. This means control value is maintained between page postbacks. View state is implemented using _VIEW STATE, a hidden form field which gets created automatically on each page. You can't transmit data to other page using view state.

2-Query String :-Query string can maintain limited state information. Data can be passed from one page to another with the URL but you can send limited size of data with the URL. Most browsers allow a limit of 255 characters on URL length.


3-Hidden Field :-Hidden field is a control provided by ASP.NET which is used to store small amounts of data on the client. It store one value for the variable and it is a preferable way when a variable's value is changed frequently. Hidden field control is not rendered to the client (browser) and it is invisible on the browser. A hidden field travels with every request like a standard control’s value.

4-Cookies  :-Cookies are small piece of information that server creates on the browser. Cookies store a value in the user’s browser that the browser sends with every page request to the web server. 

SERVER SIDE STATE MANAGEMENT

1-Application :-The data stored in an application object can be shared by all the sessions of the application. The application object stores data in the key value pair. This object stores the data that is accessible to all pages in a given Web application. The Application object contains global variables for your ASP.NET application. 

2-Session :-Session object stores user-specific data between individual requests. This object is same as application object but it stores the data about particular user. ASP.NET creates unique session-Id for each session of the application. Session-IDs are maintained either by an HTTP cookie or a modified URL, as set in the application's configuration settings. By default, Session-ID values are stored in a cookie. 

3-Cache :-Caching is the process of storing data that is used frequently by the user. Caching increases your application’s performance, scalability, and availability. You can catch the data on the server or client. 

4-Profile :-Profile data is stored in the SQL Server database by default.









How to Reverse a String in C# .Net

How to Reverse a String in C# .Net 

Step :-1

  1. Open Microsoft Visual Studio.
  2. Then go to to "File" -> "New" -> "Project..." then select Visual C# -> Windows -> Console application.









Step :-2

Then Write the Code For The Reverse a String.
----------------------------------------------------------------------------------------------------------------------
using System;

namespace ReverseAString
{
    class Program
    {
        static void Main(string[] args)
        {
            string Str, Revstr = ""
            int Length;

            Console.Write("Enter A String : ");
            Str = Console.ReadLine();

            Length = Str.Length - 1;
            
            while (Length >= 0)
            {

                Revstr = Revstr + Str[Length];
                Length--;

            }

            Console.WriteLine("Reverse  String  Is  {0}", Revstr);

            Console.ReadLine();

        }
    }
}
--------------------------------------------------------------------------------------------------------

Source-Code Image


Step :-3

Run This Application...
Output :-      Enter A String :- DOTNET TRICKS BY VICKY RAJ
                     Reverse String Is :- JAR YKCIV YB SKCIRT TENTOD



RESULT:-



















Thank You For Visit Here !!










Thursday, 24 September 2015

Swapping Two Integer Number Without Using Temp/Third Variable in .NET

Swapping Two Integer Number Without Using Temp/Third Variable in .NET

Part-1 :: Swapping Two Integer Number without using Temp/Third Variable.


namespace SwappingWithoutUsingTempVariable
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            int b = 20;
            Console.WriteLine("First Number = {0} and Second Number = {1}",a ,b);
            a += b;
            b = a - b;
            a = a - b;
            Console.WriteLine("First Number = {0} and Second Number = {1}", a, b);
            Console.ReadLine();

        }
    }
}

Image-1 :- Console Application




Image - 2 :- Result




Thursday, 17 September 2015

ASP.NET Page Life Cycle

ASP.NET Page Life Cycle


When a page is requested by the user from the browser, the request goes through a series of steps and many things happen in the background to produce the output or send the response back to the client. The periods between the request and response of a page is called the "Page Life Cycle".
  • Request: Start of the life cycle (sent by the user).
  • Response: End of the life cycle (sent by the server).
There are seven stages that occur during the Page Life Cycle before the HTML Response is returned to the client.

(1) Page request

The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.

(2) Start

In the start stage, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBackproperty. The page also sets the UICulture property.

(3) Initialization

During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.

(4 )Load

During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.

(5) Postback event handling

If the request is a postback, control event handlers are called. After that, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.
 (There is an exception to this sequence: the handler for the event that caused validation is called after validation.)

(6) Rendering

Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to theOutputStream object of the page's Response property.

(7) Unload

The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.




Tuesday, 15 September 2015

C# Interview Question Answer

C# Interview Question Answer

PART-1

1. What is C#?
C# is an object oriented, type safe and managed language that is compiled by .Net framework to generate Microsoft Intermediate Language.

2. What are the types of comment in C#?
Single line,Multi line,XML document

3. What is the difference between public, static and void?
Public declared variables or methods are accessible anywhere in the application. Static declared variables or methods are globally accessible without creating an instance of the class. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created. And Void is a type modifier that states that the method or variable does not return any value.

4. What is an Object?
An object is an instance of a class through which we access the methods of that class. “New” keyword is used to create an object. A class that creates an object in memory will contain the information about the methods, variables and behavior of that class.

5. Define Constructors?
A constructor is a member function in a class that has the same name as its class. The constructor is automatically invoked whenever an object class is created. It constructs the values of data members while initializing the class.

6. What’s the difference between an interface and abstract class?
Interfaces have all the methods having only declaration but no definition. In an abstract class, we can have some concrete methods. In an interface class, all the methods are public. An abstract class may have private methods.

7. What is the difference between Finalize() and Dispose() methods?
Dispose() is called when we want for an object to release any unmanaged resources with them. On the other hand Finalize() is used for the same purpose but it doesn’t assure the garbage collection of an object.

8. What are generics in C#.NET?
Generics are used to make reusable code classes to decrease the code redundancy, increase type safety and performance. Using generics, we can create collection classes. To create generic collection, System.Collections.Generic namespace should be used instead of classes such as Arraylist in the System.Collections namespace. Generics promotes the usage of parameterized types.

9. What are delegates?
Delegates are same are function pointers in C++ but the only difference is that they are type safe unlike function pointers. Delegates are required because they can be used to write much more generic type safe functions .

10. What is the difference between a Struct and a Class?
Structs are value-type variables and classes are reference types. Structs stored on the stack, causes additional overhead but faster retrieval. Structs cannot be inherited.

11. What are indexers in C# .NET?
Indexers are known as smart arrays in C#. It allows the instances of a class to be indexed in the same way as array.
e.g. public int this[int index]    // Indexer declaration


12. Is C# code is managed or unmanaged code?
C# is managed code because Common language runtime can compile C# code to Intermediate language.

13. What is static constructor?
Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with keyword. A static constructor does not take access modifiers or have parameters and can’t access any non-static data member of a class.

14.What is an Array?
An array is a collection of related instance either value or reference types. Array posses an immutable structure in which the number of dimensions and size of the array are fixed at instantiation.

C# Supports Single, Mult dimensional and Jagged Array.

Single Dimensional Array: it is sometimes called vector array consists of single row.

Multi-Dimensional Array: are rectangular & consists of rows and columns.

Jagged Array: also consists of rows & columns but in irregular shaped (like row 1 has 3 column and row 2 has 5 column)

15. What is an ArrayList?
ArrayList is a dynamic array. Elements can be added & removed from an arraylist at the runtime. In this elements are not automatically sorted.

16. What is BitArray?
The BitArray collection is a composite of bit values. It stores 1 or 0 where 1 is true and 0 is false. This collection provides an efficient means of storing and retrieving bit values.

17. What is HashTable?
A Hashtable is a collection of key-value pairs. Entries in this are instance of DictionaryEntry type. It implements IDictionary, ISerilizable, IDeserializable collback interface.

18. What is Queue?
This is a collection that abstracts FIFO (First In First Out) data structure. The initial capacity is 32 elements. It is ideal for messaging components.

19. What is Stack?
This is a collection that abstracts LIFO (Last In First Out) data structure in which initial capacity is 32.

20. What is a collection?
A collection serves as a container for instances of other classes. All classes implement ICollection interface which intern implement IEnumerable interface.

21. What is reflection?
Reflection is the ability to find the information about types contained in an assembly at runtime.

22. How can you sort the elements of the array in descending order?
By calling Array.Sort() and then Array.Reverse() methods.

23. What class is underneath the SortedList class?
A sorted HashTable.

24. Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.

25. Can you allow a class to be inherited, but prevent the method from being over-ridden?
Yes. Just leave the class public and make the method sealed.

26. What are the different ways a method can be overloaded?
Different parameter data types, different number of parameters, different order of parameters.

27. Difference between classes and structures?
A struct is a value type and a class is a reference type.

When we instantiate a class, memory will be allocated on the heap and when struct gets initiated it gets memory on the stack.

Classes can have explicit parameter less constructors. But structs dosn’t have this.
Classes support inheritance. No inheritance for structs.

A struct cannot inherit from another struct or class, and it cannot be the base of a class. Like classes, structures can implement interfaces.

28. What is Jagged Arrays?
The array which has elements of type array is called jagged array. The elements can be of different dimensions and sizes. We can also call jagged array as Array of arrays.

29. What is the difference between ref & out parameters?
An argument passed as ref must be initialized before passing to the method whereas out parameter needs not to be initialized before passing to a method.

30. What is the use of using statement in C#?
The using block is used to obtain a resource and use it and then automatically dispose of when the execution of block completed.

30. What is serialization?
When we want to transport an object through network then we have to convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called Serialization. 


Factorial of a Number

Recently Viewed