Thursday 16 October 2014

Horizontal Div Slider Jquery Demo

Hi friends, today i am going to show you how to slide horizontally.

If you want to implement in your project you can simply just download the project or copy past the code.

Only thing you need to import is jquery 1.4 or higher version will work. You can give css according to your requirement.


Horizontal Slider Screen 1
Screen 1

Horizontal Slider Screen 2
Screen 2

Horizontal Slider Screen 3
Screen 3

Horizontal Slider Screen 4
Screen 4

CSS:


<style type="text/css">
        #container
        {
            width: 642px;
            height: auto;
            overflow: hidden;
        }
        #list-container
        {
            overflow: hidden;
            width: 600px;
            float: left;
            border: solid 1px blue;
        }
        .list
        {
            background: #fff;
            min-width: 3400px;
            float: left;
        }
        #arrowR
        {
            background: yellow;
            width: 20px;
            height: 50px;
            float: right;
            cursor: pointer;
            margin-top: 90px;
            text-align: center;
            font-family: Arial;
            font-size: 20px;
            color: #000;
            padding-top: 25px;
        }
        #arrowL
        {
            margin-top: 90px;
            background: yellow;
            width: 20px;
            height: 50px;
            float: left;
            cursor: pointer;
            text-align: center;
            font-family: Arial;
            font-size: 20px;
            color: #000;
            padding-top: 25px;
        }
        .item
        {
            background: red;
            width: 140px;
            height: 240px;
            margin: 5px;
            float: left;
            position: relative;
            text-align: center;
            font-family: Arial;
            font-size: 20px;
            color: White;
        }
    </style>


HTML:

 <div style="width: 100%; height: auto;" align="center">
        <div style="width: 960px; height: auto;">
            <h1 style="color: grey;">
                Horizontal Slider
            </h1>
            <h2 style="color: grey;">
                (Slide When Left and Right button click)</h2>
            <div id="container">
                <div id="arrowL">
                    <
                </div>
                <div id="arrowR">
                    >
                </div>
                <div id="list-container">
                    <div class='list'>
                        <div class='item'>
                            1
                        </div>
                        <div class='item'>
                            2
                        </div>
                        <div class='item'>
                            3
                        </div>
                        <div class="item">
                            4
                        </div>
                        <div class='item' style="background: blue;">
                            5
                        </div>
                        <div class='item' style="background: blue;">
                            6
                        </div>
                        <div class='item' style="background: blue;">
                            7
                        </div>
                        <div class="item" style="background: blue;">
                            8
                        </div>
                        <div class="item" style="background: green;">
                            9
                        </div>
                        <div class="item" style="background: green;">
                            10
                        </div>
                        <div class="item" style="background: green;">
                            11
                        </div>
                        <div class="item" style="background: green;">
                            12
                        </div>
                        <div class="item" style="background: pink;">
                            13
                        </div>
                        <div class="item" style="background: pink;">
                            14
                        </div>
                        <div class="item" style="background: pink;">
                            15
                        </div>
                        <div class="item" style="background: pink;">
                            16
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


Jquery: 

<script src="Javascript/jquery-1.7.2.min.js" type="text/javascript"></script>

  <script type="text/javascript">

        $(document).ready(function() {

            var $item = $('div.item'), //Cache your DOM selector

            visible = 4, //Set the number of items that will be visible

            index = 0, //Starting index

            endIndex = ($item.length / visible) - 1; //End index


            $('div#arrowR').click(function() {

                debugger;

                if (index < endIndex) {

                    index++;

                    $item.animate({ 'left': '-=600px' });//Set width of your div here

                }

            });


            $('div#arrowL').click(function() {

                if (index > 0) {

                    index--;

                    $item.animate({ 'left': '+=600px' });//Set width of your div here

                }

            });

        });        

    </script>


Download Link: 

Download Complete Project 

 

Enjoyed this post? Share and Leave a comment below, thanks! :)

Saturday 10 May 2014

How to convert given number to word in asp.net c#

Hi friends, today i am going show you how to convert given number to word in asp.net c#.

In most of the website, application it is required to convert the number or amount in words. Following code will help you to convert a given number into words. For example, if “1234″ is given as input, output would be “One Thousand Two Hundred Thirty Four Only”


How to convert given number to word in asp.net c# Screen 1
Screen 1

How to convert given number to word in asp.net c# Screen 2
Screen 2


HTML :

 <div style="width: 100%; height: auto;" align="center">
        <div style="width: 560px; height: auto; background-color: lightgray; margin: 50px;
            padding: 25px;">
            <h1 style="margin-bottom:50px;">
                How to convert given number to word in asp.net c#
            </h1>
            <table style="width: 60%;">
                <tr>
                    <td>
                        Input Number
                    </td>
                    <td>
                        <asp:TextBox ID="txtNumber" runat="server" style="width:160px; height:25px; padding:5px;"></asp:TextBox>
                    </td>
                </tr>
                 <tr>
                    <td>&nbsp;
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                    </td>
                    <td>
                        <asp:Button ID="btnConvert" Text="Convert To Words" runat="server" style="height:25px; width:auto; padding: 0px 10px;" OnClick="btnConvert_Click" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                      <asp:Label ID="lbl2Way" runat="server" style="color:Green;"></asp:Label>
                    </td>
                </tr>
            </table>
        </div>
    </div>

 

C# Button Click Event :


//Here You need to import this package  and Num2Wrd class NumberToEnglish file. You can download class file from below link.
using Num2Wrd;
 protected void btnConvert_Click(object sender, EventArgs e)
    {
        NumberToEnglish no = new NumberToEnglish();
        string currency = no.changeCurrencyToWords(Convert.ToInt64(txtNumber.Text.Trim()));
        lbl2Way.Text = currency.ToString().ToUpper();
    }

 

Download Link :

 Download Complete Project

 

Enjoyed this post? Share and Leave a comment below, thanks! :)

Friday 28 March 2014

Restrict Special Characters in TextBox using JavaScript in asp.net

Hi friends, today i am going show you how to Restrict Special Characters in TextBox or in Textarea  using JavaScript in asp.net.

Restrict Special Characters in TextBox using JavaScript in asp.net
Screen 1
I have two method to do it in javascript.

First Method:

In this method you only want to add "RestrictHtmlCharacter-Tags.js" file in order to restrict special character in textbox.

Using this method you don't need to add anything to textbox. Only you have to do one thing only call that "RestrictHtmlCharacter-Tags.js" js file in your page and it will restrict all the textbox entering special character. For this you have to add jquery 1.7.2.min.js

Click here to download RestrictHtmlCharacter-Tags.js

If you have update panel on your page please add following initializing code to initialize the  "RestrictHtmlCharacter-Tags.js".

        //Restrict HTML Character
        $(document).ready(function() {
            try {
                RestrictHtmlCharacter();                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(RestrictHtmlCharacter);
            }
            catch (err) {
            }
        }); 

 Add this following file in head tag:

<script src="Script/jquery-1.7.2.min.js" type="text/javascript"></script>

<script src="Script/RestrictHtmlCharacter-Tags.js" type="text/javascript"></script>

 Using this way you don't need too add anything in textbox only add this javascript file.

Second Method:

The second method to do the same is following:

The script works in such a way that the TextBox will accept only alphabets, numbers i.e. alphanumeric values with some allowed special keys, thus unless a special character key has been specified to be excluded it won’t be accepted.

HTML:

<div align="center" style="width: 100%;">
        <div style="width: 300px;">
            <fieldset>
                <legend>Restrict Special Character</legend>
                <br />
                Note: Special character <b>not</b> allowed.
                <br />
                <br />
                <asp:TextBox ID="txtSearch" runat="server" onkeypress="return IsCharacterRestrict(event);"
                    ondrop="return false;" onpaste="return false;" Style="font-size: 14px;
                    margin-top: 10px; height: 30px; width: 250px; color: #353535;" MaxLength="100"></asp:TextBox>
                <br />
                <br />
                <br />
            </fieldset>
        </div>
    </div>

Script:

<script type="text/javascript">
        var specialKeys = new Array();
        specialKeys.push(8);  //Backspace
        specialKeys.push(9);  //Tab
        specialKeys.push(46); //Delete
        specialKeys.push(36); //Home
        specialKeys.push(35); //End
        specialKeys.push(37); //Left
        specialKeys.push(39); //Right
        function IsCharacterRestrict(e) {
            var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
            var ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode));
            return ret;
        }
    </script>
 

Download Link :

Download Complete Project

Enjoyed this post? Share and Leave a comment below, thanks! :)

Thursday 20 March 2014

Add Timer in Javascript & Jquery in asp.net c#

Hi friends, today i am going show you how to set timer in javascript and call events or function when times up!

You can also set dynamic timer just passing the value to hidden field "hdnTimer" or you can set your own fix time.

Here is time value given below:

1200 - 20 minutes
2400 - 40 minutes
3600 - 1 Hours
7200 - 2 Hours
So on..



Timer in javascript
Screen 1
Once timer get over it fire alert.

When timer get over fires alert
Screen 2

JS :

You need to add this jquery file

  • jquery-1.7.2.min.js

     

HTML : 

<div align="center" style="width: 100%; height: auto; font-family: Arial;">
        <div style="width: 960px; height: auto;">
            <div style="background-color: #eee; width: 500px; border: 1px solid #CCC;">
                <h1>
                    Timer in Javascript and Jquery</h1>
                <div>
                    <div style="width: 150px; height: 80px; background-color: #ececec; border: 1px solid #eaeaea;">
                        <div style="padding: 20px 20px 30px 20px; color: #323232; font-family: Arial; font-size: 20px;">
                            <input type="hidden" id="hdnTimer" value="10">
                            Time Left <b id="idTimerLCD"></b>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

 

Script :

 var _timerHandle = setInterval(function() { MyTimer() }, 1000);

        function MyTimer() {
            var valueTimer = $('#hdnTimer').val();

            if (valueTimer > 0) {
                valueTimer = valueTimer - 1;
                //Get Hours Min Secs
                hours = (valueTimer / 3600).toString().split('.')[0];
                mins = ((valueTimer % 3600) / 60).toString().split('.')[0];
                secs = ((valueTimer % 3600) % 60).toString();

                if (hours.length == 1) hours = '0' + hours;
                if (mins.length == 1) mins = '0' + mins;
                if (secs.length == 1) secs = '0' + secs;

                $('#idTimerLCD').text(hours + ':' + mins + ':' + secs);
                $('#hdnTimer').val(valueTimer);
                //Set time as Page title
                document.title = $('#idTimerLCD').text();
            }
            else {
                //Here Timer get over you can call any function here
                clearInterval(_timerHandle);
                alert(" Your time is up ! \n\n Trigger button click or any function you want to execute.");
                //(Add Button name) Button click event comes here
                //$('#btnName').click();

            }
        }

 

Download Link :

Download Complete Project

Enjoyed this post? Share and Leave a comment below, thanks! :)

Wednesday 19 March 2014

AJAX Image Upload in Asp.net C#

We've got a sweet solution that uploads an image with AJAX and then immediately displays.

Ajax ,an acronym for Asynchronous Javascript and Xml is a group of interrelated web development techniques used on the client side to create asynchronous web applications.With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page.

Here we are using ajaxupload.js to upload an image and show upload button on mouse hover and mouse out same like facebook.

On mouse out hide upload button
Screen 1


On Mouse hover show upload button

On mouse hover show upload button
Screen 2

Choose image file

choose image file
Screen 3

Finally Preview of image without postback (without refreshing page)

Upload image without postback
Screen 4

JS :

You need this following javascript file to perform AJAX Image Upload they are following:

  • jquery-1.7.2.min.js

  • ajaxupload.js

HTML:

<div align="center" style="width: 100%; height: auto;">
        <div style="width: 960px; height: auto;">
            <div style="background-color: #eee; border: 1px solid #CCC;">
                <h1>
                    AJAX Image Upload in Asp.net C#</h1>
                <h4>
                    Contains front-end (jQuery) and back-end code (c#) to upload an image and display
                    the same image on screen.</h4>
                <div align="left">
                    <h4 style="margin-left: 60px;">
                        > On Mouse hover show upload button</h4>
                    <h4 style="margin-left: 60px;">
                        > On Mouse out hide upload button</h4>
                </div>
                <div style="width: auto; height: auto; margin-top: 45px; margin-bottom: 50px; margin-left: 420px;
                    overflow: hidden;">
                    <div class="pic" style="float: left; height: 160px; width: 150px; border: 1px solid #CCC;">
                        <img id="imgUser" height="160" width="150" src="Images/NoPhotoAvailable.jpg" runat="server" />
                        <div align="center" style="height: 23px; z-index: 5; width: auto; position: absolute;
                            bottom: 0px; right: 0px;">
                            <asp:Button ID="btnUpload" ValidationGroup="vgUploadImage" runat="server" Text="Upload"
                                class="btn-update" Style="border: 0px; width: 69px; height: 23px; margin: 0px;
                                background-color: #93bbe1;" />
                        </div>
                    </div>
                </div>
                <div style="width: auto; height: 80px; margin-left: 35px;">
                    <div style="height: 25px; width: auto;">
                        <asp:Label runat="server" ID="lblImageMsg"></asp:Label>
                        <asp:TextBox ID="txtImage" placeholder="Image name come here" runat="server" Style="height: 30px;
                            font-size: 16px; width: 250px;"></asp:TextBox>
                    </div>
                </div>
            </div>
        </div>
    </div>

Script :

//Ajax Upload Script
        $(function() {
            new AjaxUpload('#<%=btnUpload.ClientID %>', {
                action: 'UploadHandler.ashx?Image=True',
                onComplete: function(file, response) {
                    debugger;
                    if (response != null) {
                        $('#<%=imgUser.ClientID %>').attr('src', response.toString());
                        document.getElementById("<%=txtImage.ClientID %>").value = file.toString();
                    }
                    else {
                        alert('Response is null!!!');
                    }
                },
                onSubmit: function(file, ext) {
                    if (!(ext && /^(jpeg|png|gif|bmp|jpg)$/i.test(ext))) {
                        alert('Invalid Image Format.');
                        return false;
                    }
                }
            });
        });

// If you don't want to show upload button on mouse hover and out just remove this code.

//On mouse hover and mouse out show/hide button code
        $(document).mousemove(function(e) {
            var $targ = $(e.target);
            if ($targ != "") {
                if ($targ.closest('.pic').length || $targ.is('.pic').length || $targ.closest('input[type=file]').length || $targ.is('input[type=file]').length) {
                    $('#<%=btnUpload.ClientID %>').show();
                }
                else {
                    $('#<%=btnUpload.ClientID %>').hide();
                }
            }
        });

Handler Code :

if (context.Request.QueryString["Image"] != null && context.Request.QueryString["Image"].ToString() != "")
        {
            if (context.Request.Files[0] != null && context.Request.Files[0].ToString() != "")
            {
                HttpPostedFile postedFile = context.Request.Files[0];

                string ImagePath = "UploadedImage/";
                postedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath(ImagePath) + postedFile.FileName.ToString());

                context.Response.Write(ImagePath + postedFile.FileName.ToString());
                context.Response.End();
            }
        }

Download Link :

Download Complete Project

Enjoyed this post? Share and Leave a comment below, thanks! :)