Showing posts with label AJAX. Show all posts
Showing posts with label AJAX. Show all posts

Thursday, April 3, 2014

Ajax MutuallyExclusiveCheckBoxExtender in ASP.NET

Earlier when we didn’t Ajax we were using JavScript to make Mutually exclusive Check boxes. Otherwise you have to use radio buttons. So make it easier for the .NET developers Microsoft introduced MutuallyExclusiveCheckBoxExtender in AJAX.
It required hardly few lines of codes and it is very easy and simple to understand. In this article I am taking you through this interesting control which you can use in your application whenever you require Mutually Exclusive CheckBox.
First we will design a sample webpage by adding few check boxes. Your sample page design may look like below,
image

Thursday, January 23, 2014

Ajax Animation Extender control

Are you thinking of decorating your website with some animation? Then there is one simple and useful control in AjaxControlToolkit named Animation extender which help you to give excellent animation to your pages.

You can apply animations to target control when some events likes, OnLoad, OnClick, OnMouseOver, or OnMouseOut raised. Here I am trying to explain how this Ajax Animation Control will work.

STEP : 1 Create a new webform

Create a new webform in ASP.NET. Drag and drop ToolScriptManager, Panel and a Animation Extender control.

animationextender

STEP 2 : Create a CSS class to the panel

Here I am using a panel for animation which is the target control. First I created a style sheet for the panel.

<style>
     .animationPanel
        {
        position : absolute;
        height : 250px;
        width: 300px;
        top: 100px;
        left: 400px;
        border-width: 2px;
        border-color:red;
        border-style:solid;
        }
        </style>

STEP 3 : Write animation properties

First I set animation property for the text inside the panel and then I set the animation for panel. Here I am doing the animation sequentially. I wrote the code on click event of the panel.

So the entire .aspx page looks like below.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Ajaxanimation.aspx.cs" Inherits="Blog.Ajaxanimation" %>
 
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>AjaxAnimation</title>
    <style>
     .animationPanel
        {
        position : absolute;
        height : 250px;
        width: 300px;
        top: 100px;
        left: 400px;
        border-width: 2px;
        border-color:red;
        border-style:solid;
        }
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <br />
         <asp:Panel ID="ajaxPanel" runat="server" CssClass="animationPanel">
                    Click me!!! I will move...<br><br><br>
             <div id ="info">
             Thanks for vising asheej.blogspot.com<br>
             You are reading the article related to AJAX animation extender
                 </div>
            </asp:Panel>
 
        <asp:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="ajaxPanel">
            <Animations>
                 <OnClick>
 
        <Sequence><%-- Sequance is used to do the animation sequantially --%> 
 
            <%-- Below code will help you to move the Panel --%> 
 
 
                      
            <Parallel AnimationTarget="info" Duration=".2">
                <Color PropertyKey="color"
                        StartValue="#0000CD" EndValue="#FF0000" />
                <Color PropertyKey="borderColor"
                        StartValue="#0000CD" EndValue="#FF0000" />
            </Parallel>
 
            <Parallel AnimationTarget="info" Duration=".2">
                <Color PropertyKey="color"
                        StartValue="#FF0000" EndValue="#666666" />
                <Color PropertyKey="borderColor"
                        StartValue="#FF0000" EndValue="#666666" />
            </Parallel>
 
                <Parallel AnimationTarget="flyout" Duration=".1" Fps="30">
                <Move Horizontal="200" Vertical="-75" />
                <Resize Height="300" Width="300" />
                <Color AnimationTarget="info" PropertyKey="backgroundColor"
                        StartValue="#ADFF2F" EndValue="#00FFFF" />
            </Parallel>
            
        </Sequence>
    </OnClick>
          
            </Animations>
        </asp:AnimationExtender>
 
    </div>
    </form>
</body>
</html>
 

STEP 4 : Build the solution and run the application

After running the code the result should be looks like this:

ajaxanimation

 

AnimationExtender Control properties:

  • TargetControlID : It is the ID of the control to which animation occurs.
  • OnLoad             : Set the animation when the page is loaded
  • OnClick             : Set the animation when the target control is clicked
  • OnMouseOver   : Set the animation when the mouse moves over the target control
  • OnMouseOut     : Set the animation when the mouse moves out the target control
  • OnHoverOver    : Set the animation when the mouse moves over the target control. But it stop the OnHoverOut  animation before it plays.
  • OnHoverOut      : Set the animation when the mouse moves out the target control. But it stop the OnHoverOver  animation before it plays.

Wednesday, January 22, 2014

Ajax rating Control

Are you planning to use Rating Control in your application from Ajax Control toolkit? This article is trying to give information on AJAX Rating Control and how to use this control. The main purpose of AJAX Rating Control is to give a chance to user for rating or reviewing content in your website.

To use Ajax Rating Control, first we have to install Ajax control toolkit. If you haven’t installed AjaxControlToolkit you may refer my article

Let me show you how I used Ajax Rating control.

Step 1 : Create .aspx page

First we need to add One Label, ToolkitScriptManager and Ajax rating Control to the webpage.

Rating1

Do you have any doubt, why I have used ToolkitScriptManager instead of ScriptManager? First I dropped ScriptManager in the webpage but while running, I got an error “0x800a138f - JavaScript runtime error: Unable to get property 'UI' of undefined or null reference” like below.

Rating2

This exception can be avoided using toolscriptManager because most of the controls from AjaxToolKit work using Ajax script. ToolkitScriptManager adds most of the updated Ajax Script.

Step 2 : Create CSS files and save images

Here I am using 3 images to show the state (Empty,Filled, Saved) of rating control. For that you need to create a folder in your project root directory and save three star images for visible star, star in waiting mode and star in filled mode.

Now the time for adding CSS class in the head section.

.filledRatingStar {
    background-image: url(Images/FilledStar.png);
}
.emptyRatingStar {
    background-image: url(Images/EmptyStar.png);
}
.savedRatingStar {
    background-image: url(Images/SavedStar.png);
}

Step 3 : Set some properties of Ajax rating control

Some properties need to set to Ajax rating Control. They are :

  • CurrentRating - Initial rating value
  • Direction        - Orientation of the stars
  • MaxRating     -  Initial rating value
  • EmptyStarCssClass - CSS class for star in empty mode
  • FilledStarCssClass   - CSS class for star in filled mode
  • StarCssClass          - CSS class for a visible class
  • WaitingStarCssClass - CSS class for the star in waiting mode

After doing all the above 3 steps,the source page should look like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RatingControl.aspx.cs" Inherits="Blog.RatingControl" %>
 
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
 
.ratingStar {
    font-size: 0pt;
    width: 15px;
    height: 50px;
    margin: 0px;
    padding: 0px;
    cursor: pointer;
    display: block;
    background-repeat: no-repeat;
}
 /*You need to make sure that Images folder is created in your Project root directory and copy the images in this folder */
.filledRatingStar {
    background-image: url(Images/FilledStar.png);
}
.emptyRatingStar {
    background-image: url(Images/EmptyStar.png);
}
.savedRatingStar {
    background-image: url(Images/SavedStar.png);
}
    </style>
 
</head>
<body style="height: 83px">
    <form id="form1" runat="server">
    <div>
           
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
 </asp:ToolkitScriptManager>
                <asp:Label ID="lblrate" runat="server" Text="Rate this blog"></asp:Label>
        
        <asp:Rating ID="Rating1" runat="server" RatingAlign="Horizontal"
            CurrentRating ="1"
            EmptyStarCssClass="emptyRatingStar" 
            FilledStarCssClass="filledRatingStar" 
            RatingDirection="LeftToRightTopToBottom" 
            StarCssClass="ratingStar" 
            WaitingStarCssClass="savedRatingStar" 
            Direction="LeftToRight">
        </asp:Rating>
    
    </div>
    </form>
</body>
</html>

Output

rating3

Hope you enjoy reading this article, if you have any comment please post below…

Tuesday, January 21, 2014

Could not load file or assembly 'AjaxMin, Version=4.97.4951.28478, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f' or one of its dependencies. The system cannot find the file specified.

This is one of the common error you get when you start using AJAX first time in your project. Nothing to panic about this, you can easily resolve the error “System.IO.FileNotFoundException: Could not load file or assembly 'AjaxMin, Version=4.97.4951.28478, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f' or one of its dependencies. The system cannot find the file specified.” by copying the missing dll in the correct folder.

image

If you look at the error once again you may notice that error clearly suggest it cannot find the assembly 'AjaxMin’ which means once you open your project bin folder you may not find the 'AjaxMin.dll’ file.

So to resolve this issue what you have to do is, search for 'AjaxMin.dll’ and copy this into the project bin folder.

image

After copying this 'AjaxMin.dll’ in your project bin folder try to run the application and see if it works fine.

Wednesday, October 23, 2013

How to use Ajax FilteredTextBoxExtender

Did you ever think of getting a ready made textbox with validation in ASP.NET? In this article I am going to explain you an Ajax control names FilteredTextBoxExtender. This control will help you to filter the user input without any additional script or coding.

Advantage of FilteredTextBoxExtender is there is not much configuration required. IT has only few properties.

1. TargetControlID—> You may specify the control you wanted to filter.

2. FilterType—> Here you mention what kind of filter you want to apply on your textbox control.

3. ValidChars—>As it’s name suggests you may enter the valid characters user supposed to enter in your textbox.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FilteredTextbox.aspx.cs" Inherits="Blog.FilteredTextbox" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </ajaxToolkit:ToolkitScriptManager>
        <br />
        <asp:Label ID="Label1" runat="server" Text="Please Enter Only Numeric Value"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <ajaxToolkit:FilteredTextBoxExtender ID="TextBox1_FilteredTextBoxExtender" runat="server" Enabled="True" TargetControlID="TextBox1" ValidChars="0123456789" FilterType="Numbers">
        </ajaxToolkit:FilteredTextBoxExtender>
    </div>
    </form>
</body>
</html>
Output will be like below,
FilterType="LowercaseLetters"

LowerCase

FilterType="UppercaseLetters"

UppercaseLetters

FilterType="Numbers"

Numbers

Hope you enjoyed this article. As usual your comments are always welcome.

Saturday, September 21, 2013

0x800a138f - JavaScript runtime error: Unable to get property 'UI' of undefined or null reference

You might be wondering what is this error and what you have to do to resolve “0x800a138f - JavaScript runtime error: Unable to get property 'UI' of undefined or null reference” error. Here is the answer for you.

Reason for this error: This error normally occurs when you use ScriptManager, like below, because most of the controls from AjaxControlToolKit work using Ajax script unfortunately many Ajax scripts are not updated in ScriptManager.

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager> 

image

Solution to resolve this error: You have to use ToolkitScriptManager instead of ScriptManager. ToolkitScriptManager adds most of the updated Ajax Script. Your code after changing must be like below,

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
 </asp:ToolkitScriptManager>

After changing to ToolkitScriptManager run your project and see the output.