My Profile

Showing posts with label ASP.Net Controls. Show all posts
Showing posts with label ASP.Net Controls. Show all posts

Thursday, February 10, 2011

Panel Control



It is equivalent to HTML <div> tag. It is a container, where we can place other controls inside it.

It will be helpful for grouping the content as well as scrolling functionality inside the form.

 How to use panel?

Place the control on the form, goto source view and type all the content required inside panel tags. Content can be simple text or other controls also.
Provide height, width properties for a panel and then enable scroll bars using “ScrollBars” property, which is an enumerated property with values vertical, horizontal, Both, Auto.

On rendering, panel will be converted to HTML <div> tag.

Try yourself the following example:

“Design a form with 4 “LinkButtons” saying Personal, Experience, Academics and Preview. When user clicks personal, form should provide inputs for entering personal details, experience- It should take experience details and similarly academic details. When user click on Preview then we must display all entered details as one Resume”.

 
---------------------------------------------------------- 
** If you like this post please like our page in 
facebook " Dot Net Support" .

How to use MultiView Control?




We’ll see how to use this control in a step wise manner.

Step 1: In a form place common (common to all the views) content like image and LinkButtons on the top of the form.

Step 2: Create “MultiView” Control and place required views inside it using “View” control. Design View content according to the requirement.

Step 3: MultiView control has “ActiveViewIndex” property, which is used to specify the view to be displayed. Its default value is “-1”. 

Step 4: In created LinkButtons write code to display the required view like:
                   MultiView1.ActiveViewIndex = 1;

Example: with this example we can get clear idea about how to use MultiView.

Step 1: design the form as following.




Step 2: Coding

Under User Info [LinkButton] click Event:
    MultiView1.ActiveViewIndex = 0;

Under Images [LinkButton] click Event:
    MultiView1.ActiveViewIndex = 1;

Under Contact Us [LinkButton] click Event:
    MultiView1.ActiveViewIndex = 2;

That’s it... You’re done!!

---------------------------------------------------------- 
** If you like this post please like our page in 
facebook " Dot Net Support" .

Some standard and Rich controls


In the previous post, we have worked with generic collections and Data Binding

Now we are ready to move forward i.e., to validations.
 
Before going to that we’ll see some more standard and rich controls.

In this post, we are going to see 3 rich controls:
·        
  •     MultiView
  • ·       View
  • ·       Panel


Let’s see one by one.

MultiView:
          It is also a rich control of ASP.Net and we can use it to display multiple views in a page, normally when we have lot of content in a page then we divide it into multiple pages which is not preferred method today. We can use MultiView control and display multiple pages data into multiple views of this control.

          A MultiView is a collection of views and every view is represented with another control called view.

View:
          We cannot use View control or MultiView control alone i.e., we should use these two controls together.

In order to display different pages in different views of MultiView, first take MultiView and then inside it take as many number of Views as we want(to some limit otherwise performance degrades) and then design each page in each view.

---------------------------------------------------------- 
** If you like this post please like our page in 
facebook " Dot Net Support" .

Generic Collections


In the previous program, we have used ArrayList class which is not preferred with respect to performance. i.e., as the classes under System.Collections undergo Boxing and Unboxing, the performance of the application degrades. So, System.Collections is not much preferred to be used.

In .Net generic classes are provided for better programming.
“System.Collections.Generic” is the namespace under which all the generic classes are provided. One of the important generic class is List<T>. it is the class inside it which is a collection of type T. T is a type like int, string, Employee etc.,

Example:       List<int> obj;
//List<int> is the class inside it which is a collection of type int.
//obj is the variable of that collection class.

Example: In the previous example modify the utility class as following:

Using System.Collections.Generic;
Public class utility
{
            Public static List<string> GetCountries()
            {
                        List<string> obj = new List<string>();
                        obj.Add(“United States”);
                        obj.Add(“India”);
obj.Add(“Australia”);
obj.Add(“United Kingdom”);
                        return obj;
            }
}

That’s it… the program will run perfectly. No need to change anything in the form code.
This is the advantage we’ll get if we maintain code file separately instead of combining code with the form.

Hope you understood how to handle generic classes and data binding.
Check yourself whether you’re clear or not with the following exercise.

“take one List control for Countries and another list control for Players, whenever user selects one country the corresponding players should come in second List control. Now take another list control for features of player, whenever user selects player atleast 5 features of that particular player should come in 3rd List control. And also take an image control display the player picture when the player is selected along with the features.”

---------------------------------------------------------- 
** If you like this post please like our page in 
facebook " Dot Net Support" .

ASP.Net Folders - 2


Let’s understand the concept Data Binding with an example.

Example: In this example we’ll see about APP_Code, Data Binding and System.Collections.

Before going into the example let’s know about one important collection which is now going to use in this example i.e., “ArrayList”.

ArrayList: It is one class in System.Collections namespace which is used to store elements of different types.

Now we’ll do the example step wise…

Step 1: In “Solution Explorer” right click on our Project and select “Add Asp.Net Folder ” à App_Code.

Step 2: Right click on App_Code and select “Add New Item” à select “Class” à name it as “utility”.
          Result: “utility.cs” will be added to our project under App_Code folder.

Step 3: In this class write a method GetCountries() that returns ArrayList as follows:
          using System.Collections;
          public class Utility
          {
                   public static ArrayList GetCountries()
                   {
                             ArrayList obj = new ArrayList();
                             obj.Add(“United States”);
                             obj.Add(“India”);
                             obj.Add(“Australia”);
                             obj.Add(“United Kingdom”);
                             return obj;
                   }
          }

Step 4: Create a Web Form with LinkButton saying “Display Contries” and also create some List Cotrols to present data from data object.
          In LinkButton write code to get countries from Utility class and map it to List Controls. Mapping is done with a property “Data Source” and to present data, a method called “DataBind()”.

è Design the form as follows:



Note: I displayed the control names in the picture itself with paint not using Visual Studio :p lolz.

Coding:
Under LinkButton Click Event:
BulletedList1.DataSource = Utility.GetCountries();
BulletedList1.DataBind();

CheckBoxList1.DataSource = Utility.GetCountries();
CheckBoxList1.DataBind();

DropDownList1.DataSource = Utility.GetCountries();
DropDownList1.DataBind();

RadioButtonList1.DataSource = Utility.GetCountries();
RadioButtonList1.DataBind();

ListBox1.DataSource = Utility.GetCountries();
ListBox1.DataBind();

Output you‘ll gets as follows:


Ok... Friends... I Hope you understood how we provide data to the list controls using data binding concept.
Try yourself with the example I’m giving you

“Take a Link button or any PostBack” control and a two List Controls one for contries and another for states. Get the countries into the countries list control as we did above and when ever user select one of the countries the states List box should show all the corresponding states to that country. Try yourself this example in Data binding method not in normal method”

**If u want the solution for this Contact me ….


---------------------------------------------------------- 
** If you like this post please like our page in 
facebook " Dot Net Support" .

Wednesday, February 9, 2011

ASP.Net Folders



Friend z… Hello again.

In the previous post we have seen what Data Binding is and what classes we use to make use of this wonderful concept “Data Binding”.

We discussed about the namespaces Collections and Collections.Generic briefly. Now we’ll go in depth of this concept.

Before going to that we need to know about the ASP.Net folders.

Generally we maintain folders in our project to manage or organize it easily like for example maintaining a folder called “Images” for all the images in our project makes us easy to work with images. We can create our own folders for different types of resources.

Apart from our own folders we can use ASP.Net pre-defined folders which are for particular purposes. It is always recommended to use these folders as they provide good security, deployment, accessibility etc,. 

I’m listing these pre-defined folders here: 




To add an ASP.Net folder to your project
Go to “solution explorer” --> right click on our project --> select “Add ASP.Net Folder” -->  choose your desired folder.

Let’s look at some of these briefly which are going to use now.

APP_Code: It is one of the ASP.Net folder which is provided for writing all code related content. When we distribute the application, this folder content is automatically converted into .Net library assembly i.e., “.dll”

APP_Data: It is another commonly used folder which is provided to store data related content like Database, XML, Text files etc.,

---------------------------------------------------------- 
** If you like this post please like our page in 
facebook " Dot Net Support" .

Working with List controls in Data Binding Method/Runtime Method



Till now we have done with these controls using static values by manually entering using properties. Now we are moving one step forward and make these controls dynamic.

Here we got a new word “Data Binding”; let’s have a look at this in detail

Data Binding:

It is a process where we create “data object” and bound it to the “control object” for getting effective presentation.

Data Object:      
          It means an object which stores data inside it and mostly as group of elements. .Net provides many objects which can be used to prepare data objects. Some of the important namespaces where these classes are present are:

·       System
·       System.Collections
·       System.Collections.Generic
·       System.Data
and few more…




Q: what is a collection and is it preferred to use Collections in .Net?

A collection is one structure in .Net which is similar to an array but with lot of functionality and also with no limitations in storing the type of data in elements.

·       System.Collections: It is one of the oldest namespace in .Net which provides collection classes. All classes in this are replaced in higher versions of .Net i.e., starting from v2.0. One main reason to change them is to avoid Boxing/Unboxing operations, which these all classes undergo.

Boxing and Unboxing:
If a value type is stored on managed heap as a reference type we call it as “Boxing”.
          Int x = 100;
          Object obj = x;    //Boxing
If that reference type is again converted back into value type we call it as Unboxing. But here implicit conversion will not take place. We need to perform an explicit conversion.
          Int y = (int) obj;   //Unboxing

·       System.Collections.Generic: It is the new namespace which is most used today in .Net and it is recommended to use this namespace instead of System.Collections.

 
Note:  Working with List controls with Data Binding concept is the most preferred way of working with these controls than working with design time options.


---------------------------------------------------------- 
** If you like this post please like our page in 
facebook " Dot Net Support" .

More Navigation related Controls


Hi friendz, hello again..

In the previous post we have seen different methods and some controls for navigating from one page to another page. Now I’m going to share some Rich controls which are also used for good navigation and they are also called as ASP.Net navigation controls.

I’ll list some of these controls now.

  • ·       Menu
  • ·       SiteMapPath
  • ·       TreeView
Note: we can find these controls under the “Navigation” tab of toolbox.


They are also like List Controls which maintain a collection for their navigation items.
Usage:
·       They can be used with properties at design time.
·       They can be used more effectively using “DataBinding” concept.
Case 1: To use these controls with design time options :
          Place the control and using “smart tag” or “properties” window provide input (static) for the control.
          To see the smart tag, select the control then we can see a small right arrow at the top right of the control which is nothing but small tag.


Fig: Menu Control with “smart tag”

          To see properties window select the control and either press F4 function key or goto view menu and select Properties window.

          Additionally “auto format” option and many other properties to customize the appearance are also provided. We can use them to present well designed output without any knowledge of HTML, JavaScript, AJAX etc., 

          Here I mentioned HTML, Java Script, Ajax because all these are already done and provided as these rich controls to us. It takes lot of time to prepare this rich control manually. We just need to do is to drag and drop the control and utilize the maximum functionality provided by these controls.

---------------------------------------------------------- 
** If you like this post please like our page in 
facebook " Dot Net Support" .

More Navigation Controls

Using PostBackUrl Property of PostBack Controls:

This is the 3rd method for navigation from one page to other page. It is quite simple than the above two methods of navigation. In this method we are not going to write any coding rather we just set a property “PostBackUrl” of the PostBack Controls like Button, LinkButton, ImageButton etc., . This property allows user to submit form to other form of web instead of same form (normal case). Using this property also we can navigate from one page to other page of the website.
It can also carry values while navigating. (it is a new feature added in ASP.NET 2.0) and it is also called as Cross-Page PostBack.

Note: For a control where we specify PostBackurl, no code should be written as it ignore that submit code.
Controls like CheckBox, RadioButton can do only straight PostBack.


HyperLink Control of ASP.NET :

Using HyperLink also we can provide navigation to other forms. 
Just place HyperLink Control and set “NavigateUrl” property to the page that we want to navigate.
  

HTML  HyperLink called <a> tag or anchor tag:


                    <a href = “url” >Text</a>

Here “a” refers to anchor tag, which makes the text as hyperlink. And “href” refers to hyperlink reference. The text in between <a> and </a> tags will be displayed as hyperlink.



---------------------------------------------------------- 
** If you like this post please like our page in facebook

Sunday, February 6, 2011

Server.Transfer

1. Server.Transfer(<pagename>)

In the previous method, we have used two different objects of ASP.NET and those are RESPONSE and REQUEST objects. These two objects are important ASP.NET objects which provide output to the client using RESPONSE object and takes input from the client using Request object.
Here the output in the sense not only displaying something on client but also giving some instructions to the client. for example, the Redirect method of the Response object gives the instruction to the client browser to navigate to the given page.
      ASP.Net is mainly built with these kind of objects. Not more than 10 important objects are available in entire ASP.NET [excluding some .Net common objects].
     Server is also on ASP.NET Object which represents or refers to the server environment where our application is running.
    Transfer method of this object provides navigation from one page to other page and this page should be located within our website only. This method also has an ability to carry values from one page to other page.

Server Environment:
The environment where our website is currently running is called Server Environment. The following figure depicts what happens at the server side.



Here in the figure the three objects are shown that are as follows:
·       Response: It is used to provide output to the client, an output may be an instruction to the client browser also.
·       Request: It is used to take the Inputs from the client browser.
·       Server: It represents or refers to the server environment where our current project is running. Server is a pointer object which points to the complete server environment.

Example:
               Server.Transfer(“destpage.aspx”); //correct [when the page destpage.aspx was created in our project]
               Server.Transfer(“http://www.google.co.in”); //wrong [because Google home page is not the page belong to our project]
Simply remember that Server object refers to only our website but not cross-website.
Example: You can understand more easily with the following example.
Step 1:  Goto Solution Explorer à Right click and Add New Item à select “Web Form” à name it as “ServerNavig.aspx” 
Step 2: Design the page as following. 


Controls Used:
Payments and Google --> LinkButton
Input for acc.no and name --> TextBox
Submit button --> Button
Step 3:  Create another page with name result.aspx and design as following



Step 4: Coding
·       Under the Payments[LinkButton] click Event [double click on it and write the following code]

                 Server.Transfer(“payments.aspx”);

//here create a page with name payments.aspx

·       Under the Google[LinkButton] click Event [double click on it and write the following code]

                  Server.Transfer(“http://www.google.co.in”); //wrong

·       Under the Submit[Button] click Event [double click on it and write the following code]

                Server.Transfer(“result.aspx”,true);

//here the result.aspx page is which we created above and the second argument is important here, which is a Boolean property which specifies whether to transfer the values of the current page to destination page or not. True indicates to pass the values to the other form. It transfers all the values of the form. We don’t have an option to send only some values.

·       Under Page_Load event of result.aspx page [double click on the form and write the following code init]

                TextBox1.text = Request[“TxtAccNo”];
                TextBox2.text = Request[“TxtName”];

//in the previous method of navigation (Response.Redirect()) we are writing the Query String, so we know the name for the values to read. But here in this method we are not writing any query string just we are mentioning whether to pass values are not using Boolean property. So in order to read values in this case we use the name for values same as the control name [ID] in which the value is present.

//Save all the project Content and Run it too see the result.


Note:
Server.Transfer doesn’t update the browser URL as it navigates to new page at server only. Whereas,
Response.Redirect will update browser URL as it redirects via browser instead of directly at server.


Differences Between Response.Redirect and Server.Transfer
Response.Redirect                                                         Server.Transfer
1.    Can navigate to                            1. Can navigate
Any site page.                                       Within site only.
2.    Query String should be                2. No query string is
Used for sending values.                      Required, bool is   enough.
3.    Query String values                     3. Server.Transfer 
Appear in URL.                                  Values will not appear.


 ---------------------------------------------------------- 
** If you like this post please like our page in facebook

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More