Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts

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! :)

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! :)

Friday 3 January 2014

ASP.NET Themes, Skin File in ASP.NET


Themes are made up of a set of elements: skins, cascading style sheets (CSS), images, and other resources. Themes are defined in special directories in our Web site or on our Web server.

A skin file has the file name extension .skin and contains property settings for individual controls such as Button, Label, TextBox, or Calendar controls. Control skin settings are like the control markup itself, but contain only the properties you want to set as part of the theme. For example, the following is a control skin for a Button control:
<asp:button runat="server" BackColor="lightblue" ForeColor="black" />

A theme can also include a cascading style sheet (.css file). When you put a .css file in the theme folder, the style sheet is applied automatically as part of the theme. We define a style sheet using the file name extension .css in the theme folder.
Themes can also include graphics and other resources, such as script files or sound files. For example, part of your page theme might include a skin for a TreeView control. As part of the theme, you can include the graphics used to represent the expand button and the collapse button.
Typically, the resource files for the theme are in the same folder as the skin files for that theme, but they can be elsewhere in the Web application, in a subfolder of the theme folder for example. To refer to a resource file in a subfolder of the theme folder, use a path like the one shown in this Image control skin:
<asp:Image runat="server" ImageUrl="ThemeSubfolder/filename.ext" />
We can also store your resource files outside the theme folder. If you use the tilde (~) syntax to refer to the resource files, the Web application will automatically find the images. For example, if you place the resources for a theme in a subfolder of your application, you can use paths of the form ~/SubFolder/filename.ext to refer to resource files, as in the following example.
<asp:Image runat="server" ImageUrl="~/AppSubfolder/filename.ext" />


Page Themes



A page theme is a theme folder with control skins, style sheets, graphics files and other resources created as a subfolder of the \App_Themes folder in your Web site. Each theme is a different subfolder of the \App_Themes folder.

Global Themes

A global theme is a theme that we can apply to all the Web sites on a server. Global themes allow you to define an overall look for your domain when you maintain multiple Web sites on the same server.
Global themes are like page themes in that they include property settings, style sheet settings, and graphics. However, global themes are stored in a folder named Themes that is global to the Web server. Any Web site on the server, and any page in any Web site, can reference a global theme.

How to  Apply ASP.NET Themes?


We can apply themes to a page, a Web site, or globally. Setting a theme at the Web site level applies styles and skins to all the pages and controls in the site unless you override a theme for an individual page. Setting a theme at the page level applies styles and skins to that page and all its controls.By default, themes override local control settings.

To apply a theme to a Web site

 

    1. In the application's Web.config file, set the <pages> element to the name of the theme, either a global theme or a page theme, as shown in the following example:

     <configuration>
        <system.web>
           <pages theme="ThemeName" />
        </system.web>
     </configuration> 
  2. To set a theme as a style sheet theme and be subordinated to local control settings), set the styleSheetTheme attribute instead:

        <configuration>
           <system.web>
               <pages styleSheetTheme="Themename" />
           </system.web>
       </configuration> 

A theme setting in the Web.config file applies to all ASP.NET Web pages in that application. Theme settings in the Web.config file follow normal configuration hierarchy conventions. For example, to apply a theme to only a subset of pages, we can put the pages in a folder with their own Web.config file or create a <location> element in the root Web.config file to specify a folder.


To apply a theme to an individual page

 

Set the Theme or StyleSheetTheme attribute of the @ Page directive to the name of the theme to use, as shown in the following example: 

 <%@ Page Theme="ThemeName" %>

<%@ Page StyleSheetTheme="ThemeName" %> 

The theme and its corresponding styles and skins now applies only to the page declaring it.
 

Creating a Theme

 

A theme is a collection of property settings that allow you to define the look of pages and controls. You can apply this look consistently across pages in a Web application. Themes are made up of several elements: server control skins, CSS files, and other resources. In this example, you use a skin and a style sheet to create a theme. 
Themes are defined in special directories in your Web site project.


Steps to To create a theme:


1. In Solution Explorer, right-click the Web site project name, click Add ASP.NET Folder, and then click Theme.

The App_Themes folder is created automatically and a new themes folder named Theme1 is added.


2. Right-click the new Theme1 folder, and click Rename. Type Blue and press ENTER

3. Right-click the new Blue folder, and then click Add New Item.

4. In the Add New Item dialog box, select Skin File and name the file default.skin. Click Add.

5. In Solution Explorer, right-click the new Blue folder again, and then click Add New Item.

6. In the Add New Item dialog box, select Style Sheet. Name the style sheet default.css. Click Add.

The first theme is now created with an empty CSS file and server control skin file. You will edit these files in a moment, but first you need to create a page that contains a control and some HTML that the theme can be applied to. 

If you have any query feel free to comment it will be appreciated :)