Feedback Form
Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts

Thursday, June 19, 2008

Disable or stop AutoCompleteExtender (Javascript)

To disable or stop the AutoCompleteExtender from running or calling its service to load auto suggested list, (Using Javascript)

Its very simple

-Set the BehaviorID property for the AutoCompleteExtender

<ajaxToolkit:AutoCompleteExtender
runat="server"
ID="autoSuggest"
TargetControlID="SearchBox"
ServiceMethod="GetSuggestedList"
ServicePath="~/_Services/AutoSuggest.asmx"
MinimumPrefixLength="2"
CompletionInterval="1"
EnableCaching="true"
CompletionSetCount="10"
CompletionListCssClass="AutoSuggestSearch"
CompletionListItemCssClass="listItem"
CompletionListHighlightedItemCssClass="highlightedListItem"
BehaviorID="autoSuggest"
/>



Then using javascript just write:




function selectType()
{
var a = $find("autoSuggest");
a.set_serviceMethod('');
}


By setting the service method to empty, the autosuggestextender will not find the service to call and will stop working

kick it on DotNetKicks.com

Friday, May 16, 2008

Add Microsoft Ajax reference to javascript file

To use microsoft ajax library reference inside your javascript file and see the Intellisense (VS 2008) while writing your javascript code:


/// <reference name="MicrosoftAjax.debug.js" />


kick it on DotNetKicks.com

Wednesday, February 27, 2008

Pure Chat sample

As axosoft company said on their website:
PureChat is one of the most attractively priced live web chatting solutions on the market.

I see its very simple one, it a good choice if:
Your budget is not a lot
You don't want any advanced communication between your operators and users.
You don't want file transfer or sharing.

Its very simple and clear.

I made a small sample using pure chat, its very simple and working nice.

Download sample

How to make your own read this


kick it on DotNetKicks.com

Friday, February 08, 2008

SlideShowExtender Fade effect

You can make fade effect while sliding and there is a good way by using SlideShowExtender + AnimationExtender like the following good sample:

<%@ 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">
[System.Web.Services.WebMethod]
public static AjaxControlToolkit.Slide[] GetSlides()
{
return new AjaxControlToolkit.Slide[] {
new AjaxControlToolkit.Slide("AjaxToolKit/SliderShowImages/Blue hills.jpg", "Blue Hills", "Go Blue"),
new AjaxControlToolkit.Slide("AjaxToolKit/SliderShowImages/Sunset.jpg", "Sunset", "Setting sun"),
new AjaxControlToolkit.Slide("AjaxToolKit/SliderShowImages/Winter.jpg", "Winter", "Wintery..."),
new AjaxControlToolkit.Slide("AjaxToolKit/SliderShowImages/Water lilies.jpg", "Water lillies", "Lillies in the water"),
new AjaxControlToolkit.Slide("AjaxToolKit/SliderShowImages/VerticalPicture.jpg", "Sedona", "Portrait style picture")};
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
var fadein;
var fadeout;

function pageLoad()
{
var ss=$find("ss1");
ss.add_slideChanging(onChanging);

var ae=$find("ae");
var be=ae.get_OnLoadBehavior();
var an=be.get_animation();
fadein=an.get_animations()[1];
fadeout=an.get_animations()[0];

fadein.set_duration(0.5);
fadeout.set_duration(0.5);
}
function onChanging(sender, args)
{
fadein.play();
window.setTimeout("fadeout.play()", 1000);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptLocalization="true" EnableScriptGlobalization="true">
</asp:ScriptManager>
<asp:Image ID="Image1" runat="server"
Height="300"
Style="border: 1px solid black;width:auto"
AlternateText="Blue Hills image" />
<ajaxToolkit:SlideShowExtender ID="slideshowextend1" runat="server"
TargetControlID="Image1" BehaviorID="ss1"
SlideShowServiceMethod="GetSlides" PlayInterval="2000"
AutoPlay="true"
Loop="true" />
<ajaxToolkit:AnimationExtender id="MyExtender" runat="server" BehaviorID="ae" TargetControlID="Image1">
<Animations>
<OnLoad>
<Sequence>
<FadeOut Duration="0" Fps="20" />
<FadeIn Duration="0" Fps="20" />
</Sequence>
</OnLoad>
</Animations>
</ajaxToolkit:AnimationExtender>
</form>
</body>
</html>

Download Sample
Reference

Monday, February 04, 2008

SlideShowExtender Set Current Image Index, Src

I wanted to set the SlideShowExtender current image, i found just one good way to do so using simple java script code

1- Add the SlideShowExtender:

<cc1:SlideShowExtender BehaviorID="behaviorID" ID="SlideShowExtender1" runat="server"
SlideShowServiceMethod="GetSlides" PlayInterval="9000" TargetControlID="imgScreen"
UseContextKey="True" AutoPlay="true" Loop="true">
</cc1:SlideShowExtender>


2- Add the following java script code:

function changeImage(imgUrl, imageIndex){
slider1 = $find("behaviorID");
slider1._currentIndex = imageIndex-1;
slider1.setCurrentImage = imgUrl;
}

kick it on DotNetKicks.com

Friday, February 01, 2008

SlideShowExtender on slide change

How to add an onchange event to the SlideShowExtender?

-After adding your SlideShowExtender, assign the image control to it and setting a BehaviorID

<cc1:SlideShowExtender BehaviorID="behaviorID" ID="SlideShowExtender1" runat="server" SlideShowServiceMethod="GetSlides" PlayInterval="5000" TargetControlID="imgScreen"  UseContextKey="True" AutoPlay="true" Loop="true"></cc1:SlideShowExtender>

-Add the following java script code inside your html code file:

<script language="javascript" type="text/javascript">  
    function pageLoad(){ 
        var slider1;  
        slider1 = $find("behaviorID"); 
        slider1.add_slideChanging(onSlideChanging);  
    }
     function onSlideChanging(sender, args){ 
        currentSlideIndex = args.get_slideIndex();  
        //Do what you want using this index
     }
</script>



kick it on DotNetKicks.com

Friday, January 04, 2008

AnimationExtender dynamic TargetControlID

How to make one AnimationExtender which apply on more than one control based on your selection in run time?

There are many solutions available online, some are very complicated and some are not useful.

For example if you want to make something like the messages which appear when you click on password, postal code,... text controls in this yahoo registration page:

https://edit.yahoo.com/registration?.intl=us&new=1&.done=http://mail.yahoo.com&.src=ym&.v=0&.u=47furq93nrtek&partner=&.partner=&pkg=&stepid=&.p=&promo=&.last=

Sure this is not the only way to do the same as in this page, but this is how to do the same using AnimationExtender Ajax ToolKit control.

And Now how to make it:

We want to show an animated different message when we click on different TextBoxs.

1- Don't forget to add the Script Manger before using the AnimationExtender Control

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
2- Then Create the AnimationExtender control and assign any default TargetControlID property because it will not work if its empty.
<cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="TextBox2">

3- Then create the controls you will work on as you can see in the complete page code below.

4- Now the problem that the TargetControlID property can't be dynamic, so what we can do to apply the same Extender to more than one control:

We can make a small work around by adding a hidden field and using javascript we can set this hidden field to the control we need.

Then assign this hidden control value to the AnimationTargetScript:


<cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="TextBox2">
<Animations>

<OnClick>
<Sequence>
<FadeIn AnimationTargetScript="javascript:getTargetControl();" Duration="0.5" Fps="300"/>
</Sequence>
</OnClick>
</Animations>

</cc1:AnimationExtender>
<input type="hidden" id="hid" value="msg1" />


function getTargetControl()
{
  return document.getElementById("hid").value;
}

Then we want to make the function which will start the animation when clicking on a textbox control:
function animate(ele)
{
    $get("Msg1").style.opacity=0;
    $get("Msg2").style.opacity=0;
    $get("hid").value=ele;
    if ($find("AnimationExtender1")!=null)
        {
            var onclkBehavior = $find("AnimationExtender1").get_OnClickBehavior().get_animation();
            onclkBehavior.play();
        }
}
This is the complete page sample:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

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

<!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>Untitled Page</title>
<script language="javascript" type="text/javascript">
  function animate(ele)
  {
$get("Msg1").style.opacity=0;
     $get("Msg2").style.opacity=0;
     $get("hid").value=ele;
     if ($find("AnimationExtender1")!=null)
     {
         var onclkBehavior = $find("AnimationExtender1").get_OnClickBehavior().get_animation();
         onclkBehavior.play();
     }
  }
          
  function getTargetControl()
   {
       return document.getElementById("hid").value;
   }
  18:     
</script>

</head>


<body>
<form id="form1" runat="server">

 <div>
         <asp:ScriptManager ID="ScriptManager1" runat="server">
         </asp:ScriptManager>
         <cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="TextBox2">
            <Animations>
                        <OnClick>
                             <Sequence>
                                 <FadeIn AnimationTargetScript="javascript:getTargetControl();" Duration="0.3" Fps="300"/>
                             </Sequence>
                         </OnClick>
             </Animations>
         </cc1:AnimationExtender>


          <input type="hidden" id="hid" value="msg1" />
         <table style="width: 100%;">
             <tr>
                 <td>
                    <asp:TextBox ID="TextBox1" runat="server" onclick="javascript:animate('Msg1');"></asp:TextBox>
                 </td>
                 <td>
                     <div id="Msg1" style="opacity: 0; left: 781px; top: 662px; color: #FF0000;">
                         THIS IS Message 1
                     </div>
                 </td>
                 <td>
                     &nbsp;
                 </td>
             </tr>
             <tr>
                 <td>
                     <asp:TextBox ID="TextBox2" runat="server" onclick="javascript:animate('Msg2');"></asp:TextBox>
                 </td>
                 <td>
                     <div id="Msg2" style="opacity: 0; left: 781px; top: 662px; color: #00FF00;">
                         THIS IS Message 2
                     </div>
                 </td>
                 <td>
                 </td>
             </tr>
         </table>
     </div>
     </form>
 </body>
 </html>
Now everything is done, you can try and manipulate as you want, you will find it simple.