July 18, 2012

PagingBulletedListExtender Control from AJAX Control ToolKit Code Example

PagingBulletedListExtender allows alphabetic paging to the bulleted lists.
Read the below post to know how you can use the controls of AJAX Control ToolKit
http://www.dotnetissues.com/2012/07/alwaysvisiblecontrolextender-from.html


To us the PagingBulletedListExtender  set the TargetControlId of this control with the bulleted list which you wants 
to Page alphabetically .

See the below code







PagingBulletedList.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PagingBulletedList.aspx.cs" Inherits="PagingBulletedList" %>


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="aspa" %>


<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    
    <div>


    <aspa:pagingbulletedlistextender ID="Pagingbulletedlistextender1" runat="server" TargetControlID="BulletedList1"></aspa:pagingbulletedlistextender><br />
    
     <asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField ="Name" />
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:dotnettrainingConnectionString2 %>" 
        SelectCommand="SELECT [Name] FROM [Employeedetails]"></asp:SqlDataSource>
    </form>
</body>
</html>

July 17, 2012

ConfirmButtonExtender Control from AJAX Control Tool kit

To know how to use Controls from AJAX Control Toolkit follow this post
http://www.dotnetissues.com/2012/07/alwaysvisiblecontrolextender-from.html

When there is some critical Operation on a button click its a good idea to prompt  'Are you sure' message to the user and this can be easily accomplished by ConfirmButtonExtender  control from AJAXControlToolkit

Set the TargetControlId and ConfirmText Property of the ConfirmButtonExtender
As per below code sample



ConfirmButtonExtender.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConfirmButtonExtender.aspx.cs" Inherits="ConfirmButtonExtender" %>


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>


<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:scriptmanager ID="Scriptmanager1" runat="server" ></asp:scriptmanager>
    <asp:ConfirmButtonExtender ID="ConfirmButtonExtender1" ConfirmText="Are you sure want to delete this" TargetControlID="btnDelete" runat="server"></asp:ConfirmButtonExtender>
    <asp:Button ID="btnDelete" runat ="server" Text ="DELETE"    />
    <div>
    
    </div>
    </form>
</body>
</html>

when you click on the delete button below prompt will come.



AutoCompleteExtender From AJAX Control Tool Kit Code Example

To know how to use controls from AJAX Control Took Kit , you can read this post.

http://www.dotnetissues.com/2012/07/alwaysvisiblecontrolextender-from.html
Below is the cod sample for how to Use AutoCompleteExtender  Control.
Many times when we are typing in Text box we want the relevant text should come automatically after typing few letters , This functionality is being used in almost all the search engines.

To integrate this functionality we can use AutoCompleteExtender   from AJAX Control Toolkit

Drag n drop this control in Web form and set the property TargetControlID
and then Clink on Add AutoComplete Page Method on the target control as below


This will add GetCompletionList(string prefixText, int count, string contextKey) method in code -behind.
Where You have to write the Business logic to get the relevant List

I have a table 'EmployeeDetails' in DB with a column 'Name' as below

Below code I have written for the AutoComplete Name

AutoCompleteExtender .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoCompleteExtender.aspx.cs" Inherits="AutoCompleteExtender" %>


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>


<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
    
    <asp:autocompleteextender ID="Autocompleteextender1" TargetControlID="txtName"  
            runat="server" ServiceMethod="GetCompletionList" UseContextKey="True"></asp:autocompleteextender>
     <br/>
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    </div>
    
    </form>
</body>
</html>


AutoCompleteExtender .aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;




public partial class AutoCompleteExtender : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
       


    }


    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string[] GetCompletionList(string prefixText, int count, string contextKey)
    {
        SqlConnection connObj = new SqlConnection();
        //DataSet ds;
        SqlCommand objCommand;
       
        connObj.ConnectionString = ConfigurationManager.ConnectionStrings["DotNetTrainingConnectionString"].ToString();
        connObj.Open();


        objCommand = new SqlCommand("Select  Name from Employeedetails where Name LIKE'"+prefixText+"%' ", connObj);
        SqlDataReader dr;
        List<string> NameList = new List<string>();
        dr = objCommand.ExecuteReader();
        while (dr.Read())
        {
            NameList.Add(dr["Name"].ToString());




        }


        return NameList.ToArray();
    }
}


and this is how the behavior will be.


July 16, 2012

AlwaysVisibleControlExtender from AJAXControl ToolKit Code Example

AlwaysVisibleControlextender :When displaying information in the browser sometime you may want to display
some information fixed on the Browser screen ,So we can use this alwaysvisiblecontrolextender  Control
from AJAX Control Tool Kit and set the position on the screen , It will be then visible even after user has scrolled the screen.

Before know how to use this control we have to know How to integrate the AJAX Control Tool Kit in Visual Studio as it is not by default there.To add AJAX Control Tool Kit Download it from the below link
http://ajaxcontroltoolkit.codeplex.com/downloads/get/116534

After that In Toolbox right click and go to AddTab as below

Now Name the tab as you want Ex. AJAXToolKit

Then Right click on the tab and click on Choose items as below

Then Browse for the AJAXCONTROLTOOLKIT.DLL from the download location.

It will add All the controls from AJAXControlToolkit to your VisualStudio Toolbox and you can use them
as any other standard controls.

Nowto Use alwaysvisiblecontrolextender
First Drag the ScriptManager on the page and then Drag the alwaysvisiblecontrolextender

set the position of the alwaysvisiblecontrolextender  control on the page by setting properties
HorizontalOffset and  VerticalOffset
and then Set the TargetControlID Property , which will define which content has to be fixed on the screen

See the Below example

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AlwaysVisibleControl.aspx.cs" Inherits="AlwaysVisibleControl" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!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></title>
</head>

<body>
    <form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
            <asp:alwaysvisiblecontrolextender ID="Alwaysvisiblecontrolextender1" HorizontalOffset="160" VerticalOffset="140"  TargetControlID="Panel1" runat="server"></asp:alwaysvisiblecontrolextender>
 <asp:panel ID="Panel1" runat="server">
             This Text Is always visible 
            
            </asp:panel>
    </div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
       <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
         <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
           <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
             <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
              <asp:Label ID="Label6" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
       <asp:Label ID="Label7" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
         <asp:Label ID="Label8" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
           <asp:Label ID="Label9" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
             <asp:Label ID="Label10" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
              <asp:Label ID="Label11" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
       <asp:Label ID="Label12" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
         <asp:Label ID="Label13" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
           <asp:Label ID="Label14" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
             <asp:Label ID="Label15" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
              <asp:Label ID="Label16" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
       <asp:Label ID="Label17" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
         <asp:Label ID="Label18" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
           <asp:Label ID="Label19" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
             <asp:Label ID="Label20" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
              <asp:Label ID="Label21" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
       <asp:Label ID="Label22" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
         <asp:Label ID="Label23" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
           <asp:Label ID="Label24" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
             <asp:Label ID="Label25" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
              <asp:Label ID="Label26" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
       <asp:Label ID="Label27" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
         <asp:Label ID="Label28" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
           <asp:Label ID="Label29" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
             <asp:Label ID="Label30" runat="server" Text="Label"></asp:Label><br /><br /><br /><br /><br /><br />
    </form>
</body>
</html>