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

Thursday, March 28, 2013

Progress Bar in Update Panel in C#

Use below Code to have Progress Bar in ASP.net with C# using AJAX

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
<asp:UpdateProgress runat="server" ID="UpdateProgress1"
DynamicLayout="false" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<img id="Img1" runat="Server" src="<Path of Gif or motion image file>" height="12"  alt=""/>
</ProgressTemplate>
</asp:UpdateProgress>
</td>
</tr>

</table>
</ContentTemplate>
</asp:UpdatePanel

Sunday, July 1, 2012

Ajax SlideShow Example/Sample in c#


Introduction:

             Today I am going to show you the very useful sample and that is Slide show.I am showing you how to show slideshow using ajax.After Saving the images into the Folder we will going to use that images in Slide Show.

First you have to add ajax toolkit to your Project by adding a reference.

Then add a webpage Default.aspx to your project.and also make one folder name Images into project and put some images into the folder.

Default.aspx Page

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>AJAX Slidshow  Example</title>
    <style type="text/css">
        .Buttoncss
        {
            border: solid 1px #c0c0c0;
            background-color: silver;
            color: #ffffff;
            cursor: pointer;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <ajax:ToolkitScriptManager ID="scriptmanager1" runat="server">
    </ajax:ToolkitScriptManager>
    <div>
        <table style="border: Solid 3px green; width: 400px; height: 400px" cellpadding="0"
            cellspacing="0">
            <tr style="background-color: #33CC33">
                <td style="height: 10%; color: White; font-weight: bold; font-size: larger" align="center">
                    <asp:Label ID="lblTitle" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Image ID="imgslides" runat="server" Height="400px" Width="600px" />
                </td>
            </tr>
            <tr>
                <td align="center">
                    <asp:Label ID="lblimgdesc" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td align="center">
                    <asp:Button ID="btnPrevious" runat="server" Text="Prev Image" CssClass="Buttoncss" />
                    <asp:Button ID="btnPlay" runat="server" Text="Play" CssClass="Buttoncss" />
                    <asp:Button ID="btnNext" runat="server" Text="Next Image" CssClass="Buttoncss" />
                </td>
            </tr>
        </table>
        <ajax:SlideShowExtender runat="server" AutoPlay="true" ImageTitleLabelID="lblTitle"
            ImageDescriptionLabelID="lblimgdesc" Loop="true" NextButtonID="btnNext" PreviousButtonID="btnPrevious"
            PlayButtonID="btnPlay" PlayButtonText="Play" StopButtonText="Stop" TargetControlID="imgslides"
            SlideShowServicePath="Slideshow.asmx" SlideShowServiceMethod="GetSlides">
        </ajax:SlideShowExtender>
    </div>
    </form>
</body>
</html>

Now you have to Add the webservice by right click on project and Add the Item Webservice called SlideShow.asmx then remove the SlideShow.asmx.cs file just keep SlideShow.asmx and put the class file of it in App_Code Folder.for that you have to create App_Code Folder by right click on Project And add the Folder and add the SlideShow.cs file in it.


PlayButtonID - ID of the button that will allow you to play/stop the slideshow.

PlayButtonText - The text to be shown in the play button to play the slideshow.

StopButtonText - The text to be shown in the play button to stop the slideshow.

PreviousButtonID - ID of the button that will allow you to see the previous picture.

NextButtonID - ID of the button that will allow you to see the next picture.


PlayInterval - Interval in milliseconds between slide transitions in play mode.

ImageTitleLabelID - ID of Label displaying current picture's title.

ImageDescriptionLabelID - ID of Label describing current picture.

Loop - Setting this to true will allow you to view images in a round-robin Pattern.

AutoPlay - Setting this to true will play the slideshow automatically on render.

SlideShowServicePath - Path to the webservice that the extender will pull the images from.

SlideShowServiceMethod - The webservice method that will be called to supply images


Here we need to remember one point that is we need to write webmethods like following Pattern.

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public AjaxControlToolkit.Slide[] GetSlides()
{
……
……
}
Here I have used the .Buttoncss for Next,Previous and Play Button

SlideShow.cs Page Code 

using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]

public class Slideshow : System.Web.Services.WebService
{

    public Slideshow()
    {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public AjaxControlToolkit.Slide[] GetSlides()
    {
        string[] imagenames = System.IO.Directory.GetFiles(Server.MapPath("~/Images"));
        AjaxControlToolkit.Slide[] photos = new AjaxControlToolkit.Slide[imagenames.Length];
        for (int i = 0; i < imagenames.Length; i++)
        {
            string[] file = imagenames[i].Split('\\');
            photos[i] = new AjaxControlToolkit.Slide("Images/" + file[file.Length - 1], file[file.Length - 1], "");
        }
        return photos;
    }
}

SlideShow.asmx code

<%@ WebService Language="C#" CodeBehind="~/App_Code/Slideshow.cs" Class="Slideshow" %>

In SlideShow.asmx Page CodeBehind Specify the class file SlideShow which we put in App_Code folder and in that all the Logic of slide show is there.

string[] imagenames = System.IO.Directory.GetFiles(Server.MapPath("~/Images"));  //This will Fetch all the Images from the Images Folder
        AjaxControlToolkit.Slide[] photos = new AjaxControlToolkit.Slide[imagenames.Length];
//This will store the all the photos in photos object.

        for (int i = 0; i < imagenames.Length; i++)
        {
            string[] file = imagenames[i].Split('\\');
            photos[i] = new AjaxControlToolkit.Slide("Images/" + file[file.Length - 1], file[file.Length - 1], "");
        }
        return photos;

This Loop will rounded by number of Images.Photos[i] contains images information.Name,ImagePath and its Description.

new AjaxControlToolkit.Slide("Images/" + file[file.Length - 1], file[file.Length - 1], "");
This contains three parameter.
1.Image Path
2.Image Name
3.Image Description.Here I just pass Empty string in Image Description but you can pass this Parameter.


Download the Sample Code from Here
 Download

Thursday, June 7, 2012

FileUpload Progress bar using Ajax

Introduction:
                  I explained in my Previous Post about AjaxMaskEdit  in http://www.aspdotnetbank-kartik.blogspot.in/2012/02/ajax-maskedit-for-date-validator.html.Now in this Post I am going to explain you about Progress bar using Ajax AsyncFileUpload while FileUpload.

I am Going to show how to use Progressbar while Uploading the File.Here I am Going To Upload file Using FileUpload and while Uploading the File It will show you the Progress bar.First You have to add the AjaxtToolkit as a Reference.and also add the Images Folder inside Project.

Lets Look at .aspx code

Add above <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>

<head runat="server">
    <title>Example Of Progressbar</title>
    <script type="text/javascript">
        // This function will execute after file uploaded successfully
        function uploadComplete() {

            document.getElementById('<%=lblMsg.ClientID %>').innerHTML = "File Uploaded Successfully";
        }
        // This function will execute if file upload fails
        function uploadError() {
            document.getElementById('<%=lblMsg.ClientID %>').innerHTML = "File upload Failed.";
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <ajax:ToolkitScriptManager ID="scriptManager1" runat="server"/>
        <ajax:AsyncFileUpload ID="fileUpload1" OnClientUploadComplete="uploadComplete" OnClientUploadError="uploadError"
            CompleteBackColor="White" Width="350px" runat="server" UploaderStyle="Traditional"
            UploadingBackColor="#CCFFFF" ThrobberID="imgLoad" OnUploadedComplete="fileUploadComplete" />
        <br />
        <asp:Image ID="imgLoad" runat="server" ImageUrl="loading.gif" />
        <br />
        <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>

If you Look at above code UploaderStyle="Traditional" in that there are two option "Morden" and "Traditional" both have different Look for FileUploader.Here i have used Traditional.while OnUploadedComplete="fileUploadComplete" specify the Method for Uploading code in aspx.cs Page.

Now Lets Look at aspx.cs Page code : You have to just the Method fileUploadComplete in aspx.cs page.


using System.Threading;
using AjaxControlToolkit;

 protected void fileUploadComplete(object sender, AsyncFileUploadEventArgs e)
 {
            Thread.Sleep(5000);
            string filename = System.IO.Path.GetFileName(fileUpload1.FileName);
            fileUpload1.SaveAs(Server.MapPath("Images/") + filename);
  }
Here I have used Thread.Sleep Method Because If you are Going to Upload the small file then also you can see the Progress bar.Thread.Sleep(5000) will suspend the execution of code for 5 second.


Note:If your aspx Page uses any master page then specify the attribute ClientIDMode="AutoID" in <ajax:AsyncFileUpload ....> Tag


Demo:
Download the Sample Code from Here
 Download



Friday, February 10, 2012

Ajax MaskEdit For Date Validator.....


  <asp:TextBox ID="txtShipmentDate" runat="server" Width="120px" ValidationGroup="a"></asp:TextBox>    
    <asp:MaskedEditExtender ID="MaskedEditExtender1" runat="server"
        TargetControlID="txtShipmentDate"
        MaskType="Date"
        Mask="99/99/9999"
        MessageValidatorTip="true"
        CultureName="en-US"
        OnFocusCssClass="MaskedEditFocus"
        OnInvalidCssClass="MaskedEditError"
        DisplayMoney="Left"
        AcceptNegative="Left"
        ErrorTooltipEnabled="True" />
    <asp:MaskedEditValidator ID="MaskedEditValidator1" runat="server"
        ControlExtender="MaskedEditExtender1"
        ControlToValidate="txtShipmentDate"
        EmptyValueMessage="Date is required"
        InvalidValueMessage="Date is invalid"
        Display="Dynamic"
        TooltipMessage=""
        EmptyValueBlurredText="*"
        InvalidValueBlurredMessage="*" ForeColor="Red" ValidationGroup="a"/>
<br />
<asp:Button ID="submit" Text="submit" runat="server" ValidationGroup="a"/>

Property Of MaskEdit


  • MaskType - Type of validation to perform:
    None - No validation
    Number - Number validation
    Date - Date validation
    Time - Time validation
    DateTime - Date and time validation
  • Mask Characters and Delimiters
    9 - Only a numeric character
    L - Only a letter
    $ - Only a letter or a space
    C - Only a custom character (case sensitive)
    A - Only a letter or a custom character
    N - Only a numeric or custom character
    ? - Any character

    / - Date separator
    : - Time separator
    . - Decimal separator
    , - Thousand separator
    \ - Escape character
    { - Initial delimiter for repetition of masks
    } - Final delimiter for repetition of masks

    Examples:
    9999999 - Seven numeric characters
    99\/99 - Four numeric characters separated in the middle by a "/"
  • AcceptAMPM - True to display an AM/PM symbol
  • AcceptNegative - True if the negative sign (-) is allowed
    None - Do not show the negative sign
    Left - Show the negative sign on the left of the mask
    Right - Show the negative sign on the right of the mask
  • AutoComplete - True to automatically fill in empty mask characters not specified by the user
    MaskType=Number - Empty mask characters will be filled with zeros
    MaskType=Time - Empty mask characters will be filled with the current time
    MaskType=Date - Empty mask characters will be filled with the current date
    MaskType=DateTime - Empty mask characters will be filled with the current date/time
  • AutoCompleteValue - Default character to use when AutoComplete is enabled
  • Century - Default century used when a date mask only has two digits for the year
  • ClearMaskOnLostFocus - True to remove the mask when the TextBox loses focus
  • ClearTextOnInvalid - True to clear the TextBox when invalid text is entered
  • ClipboardEnabled- True to allow copy/paste with the clipboard
  • ClipboardText - Prompt text to use when a clipboard paste is performed
  • DisplayMoney - Specifies how the currency symbol is displayed
    None - Do not show the currency symbol
    Left - Show the currency symbol on the left of the mask
    Right - Show the currency symbol on the right of the mask
  • ErrorTooltipCssClass - CSS class for the tooltip message
  • ErrorTooltipEnabled - True to show a tooltip message when the mouse hovers over an invalid TextBox
  • Filtered - Valid characters for mask type "C" (case-sensitive)
  • InputDirection - Text input direction
    LeftToRight - Left to Right
    RightToLeft - Right to left
  • MessageValidatorTip - Message displayed when editing in TextBox
  • PromptChararacter - Prompt character for unspecified mask characters
  • UserDateFormat - Custom date format
  • UserTimeFormat - Custom time format
  • OnFocusCssClass - CSS class used when the TextBox receives focus
  • OnFocusCssNegative - CSS class used when the TextBox gets focus with a negative value
  • OnBlurCssNegative - CSS class used when the TextBox loses focus with a negative value
  • OnInvalidCssClass - CSS class used when the text is not valid.
  • CultureName - Name of culture to use (overrides the default page culture)
  • CultureAMPMPlaceholder - Culture override
  • CultureCurrencySymbolPlaceholder - Culture override
  • CultureDateFormat - Culture override
  • CultureDatePlaceholder - Culture override
  • CultureDecimalPlaceholder - Culture override
  • CultureThousandsPlaceholder - Culture override
  • CultureTimePlaceholder - Culture override