Saturday 23 June 2012

ListBox

List box is used to display a list of one or more item so that user can choose one or more items from it.List box displays list of item sequentially and vertically in a scrollable window.

You can add values in Listbox manually or programmatically.To add values manually firstly add your listbox control into webpage and select it a small tag will appear on right side of listbox click on it and select Edit Items.
After click on Edit Items a ListItems Collection Editor box will appear .Click on Add button and enter your item's text in Text field and item's value in Value field.Your item will successfully added into listbox.Similarly you can add more values into listbox.At last click on OK button.
Similarly you can add values into listbox from database.To add values from database click on small tag of listbox and select Choose Data Source.A new Data Source Configuration Wizard dialog box will appear.Now create a new data source or select a already created data source.
After selection of Data Source click on OK button.
To add values in listbox programmatically use the following code in PageLoad event.

   
 protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            ListBox1.Items.Add(new ListItem("Pkistan", "Pkistan"));
            ListBox1.Items.Add(new ListItem("Canada", "Canada"));
            ListBox1.Items.Add(new ListItem("Paris", "Paris"));
            ListBox1.Items.Add(new ListItem("UK", "UK"));
            ListBox1.Items.Add(new ListItem("Itly", "Itly"));
        }
    }
This code add the values in the listbox at run time.


Some Commonly Used Properties of ListBox
SelectedIndex Property:
Gets or Sets the lowest index of the selected item in the listbox.This property will return the index as an integer.
SelectedItem Property:
Gets or Sets the selected item with the lowest index in the listbox control.
SelectedValue Property:
Gets the value of the selected item in the listbox control.This property will return the value as a string.
SelectionMode Property:
Sets the selection mode of the listbox control.By using this property you can select one or more values from the listbox.











Friday 22 June 2012

How To Add Class File in ASP.NET

To add a class file into asp.net follow these steps:
step 1:
           Open your asp.net project and goto solution explorer and right click on it and choose Add New Item->Class OR Add->Class
Step 2:
            Enter your class name and click on Add button.Your class.cs file will be added successfully.


           

How To Add a New WebForm in ASP.NET

In this tutorial we are going to discuss how to add a new webform in asp.net.We perform this task step by step.
Step 1:
            Firstly open your asp.net project and goto solution explorer and right click on asp.net project file Add->New Item OR simply you can use New Item short cut.
Step 2:
           A New Item dialog box will appear choose first item which is WebForm.aspx.
Step 3:
           Enter your web form name and click on Add button.Your new webForm will be successfully added into your asp.net project.





Tuesday 19 June 2012

Hyperlink

Hyperlink control is used to navigate to the target URL when user clicks on the link.Hyperlink control and LinkButton control looks similar but there is some difference between Hyperlink and LinkButton control in ASP.NET.When user clicks on a Hyperlink control the hyperlink control does not PostBack the page to the server.It will simply post the request to the server for the URL set in NavigateURL property.While LinkButton works like a simple button but it looks like a Hyperlink so LinkButton will PostBack the page to server.One other difference is that Hyperlink control does not have a OnClick event just like in LinkButton control.

Some Commonly Used Properties of Hyperlink Control
ImageURL Property:
This property is used to gets or sets the path to an image to display for the Hyperlink Control.
IsTrackingViewState Property:
This property is used to gets a value that indicates whether the server control is saving changes to its view state.It will return a simple boolean value which represents true or false.If returned value is true that mean the control is set to save view state while in case of false the control will not save the view state.
NavigateURL Property:
This property is used to gets or sets the URL to the link to when hyperlink control is clicked.

To see more properties click on link given below:

Thursday 14 June 2012

LinkButton

LinkButton is used to create a hyperlink in a website.This control looks like hyperlink but it has a same functionality of hyperlink control ans a button control.You can use the LinkButton control by specifying Text to display in linkbutton control by either the Text property or specifying the text between the opening tag and closing tag.
When you click on a linkbutton control then linkbutton take you to desired webpage by using PostBackUrl property e,g, PostBackUrl="~/how-to-use-textbox.aspx".

Some Commomly Used Properties
Access Key Property:
Access Key is used to get or set the access key so that you can easily navigate to web sever controls.In other words we can say that access key is use to create a short cut key 
to web server controls.
IsEnabled Proerty:
Gets a value that indicating whether the control is active or not.
OnClickClient Property:
Gets or Sets the client side script that executes when a LinkButton's click event raised.
<%@ page language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void LinkButton1_Click (object sender, EventArgs e)
  {
    Label1.Text = "LinkButton is clicked.";
  }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="head1" runat="server">
    <title>LinkButton.OnClientClick Example</title>
</head>
<body>
  <form id="form1" runat="server">

    <h3>LinkButton.OnClientClick Example</h3> 
      <br />
      <h4>Click to navigate to Microsoft.com:</h4>     
      <br />
      <asp:linkbutton id="LinkButton1"
       text="Open Web site"
       onclientclick="Navigate()"
       onclick="LinkButton1_Click"
       runat="Server" />

       <br /><br />

      <asp:label id="Label1"
        runat="Server">
      </asp:label>
    </form>
    <script type="text/javascript">
      function Navigate()
      {
        javascript:window.open("http://www.microsoft.com");
      }    

    </script>
</body>
</html>

PostBackUrl Property:
The PostBackUrl property allows you to perform a cross-page post using the LinkButton control. Set the PostBackUrl property to the URL of the Web page to post to when the LinkButton control is clicked. For example, specifying Page2.aspx causes the page that contains the LinkButton control to post to Page2.aspx. If you do not specify a value for the PostBackUrl property, the page posts back to itself.


To see more properties of LinkButton control click following link:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.aspx