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


Friday, 27 December 2013

javascript - jQuery fading "Back To Top" link


Here i am explaining how to add javascript - jQuery fading "Back To Top" link

We need to style and position it. Here I’m setting its position to fixed and adding the image of "Back To Top". I also added the Fade In and Fade Out effect.

Back To Top

Script

//Add This Jquery CDN
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.1.min.js">
 </script>


//A Simple FadeIn and FadeOut Effect Back to top
<script type="text/javascript">
        $(function() {
            $(window).scroll(function() {
                if ($(this).scrollTop() != 0) {
                    $("#toTop").fadeIn();
                }
                else {
                    $("#toTop").fadeOut();
                }
            });
            $('#toTop').click(function() {
                $('body,html').animate({ scrollTop: 0 }, 800);
            });
        });
</script>


CSS

<style type="text/css">
        #toTop
        {
            position: fixed;
            bottom: 50px;
            right: 30px;
            width: 180px;
            height:100px;
            padding: 5px;         
            cursor:pointer;
            display: none;
        }
</style>

 

HTML

//This is the Fixed div
<div id="toTop">
        <img src="images/BackToTopArrow.png" style="width: 250px;
            height:100px;" alt="back to top" title="back to top" />
</div>


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

Tuesday, 24 December 2013

Facebook Style Cross-Browser Jscroll Pane



jScrollPane is a cross-browser jQuery plugin which converts a browser's default scrollbars (on elements with a relevant overflow property) into an HTML structure which can be easily skinned with CSS.

How to use

It is very simple to use JScrollPane. You will need to download the necessary files and place them on your server. Then you just need to include the relevant files in the <head> tag of your document.

You can get needed file by downloading attached file below clicking on Download Link

Screen shot :





Here is the example :

CSS

//styles needed by jScrollPane
<link href="CSS/jquery.jscrollpane.css" rel="stylesheet" type="text/css" />

Script Path



//styles needed by jScrollPane
<link type="text/css" href="style/jquery.jscrollpane.css" rel="stylesheet" media="all" />

//latest jQuery direct from google's CDN
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
 

Script

//Call the jScrollPane  
<script type="text/javascript">
        $(document).ready(function() {
            $('.MultipleDivScroll').jScrollPane();
        });
</script>

 

Body

//body demo content for jScrollPane
<body>
    <div align="center" style="width: 100%;">

        <h1>
            Facebook Style JScroll Pane</h1>
        <div align="left" id="divScrollPane" class="MultipleDivScroll" style="width: 180px;
            height: 300px; border: solid 0px; outline: none !important;">
            <p>
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit,Ut wisi enim ad minim veniam,
                sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                Ut wisi enim ad minim veniam.</p>
            <p>
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit,Ut wisi enim ad minim veniam,
                sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                Ut wisi enim ad minim veniam.</p>
            <p>
                Lorem ipsum dolor sit amet, consectetuer adipiscing elit,Ut wisi enim ad minim veniam,
                sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                Ut wisi enim ad minim veniam.</p>
        </div>
    </div>
</body> 


Download Link


  
Reference Link For More Details on jScrollPane

http://jscrollpane.kelvinluck.com/

If you have any query comment will be appreciated :)

Upload Multiple Images with Preview Using FileUpload Control in ASP.NET Using Javascript


Here I will discuss with you one of control, the feature of FileUpload control in ASP.NET. Using FileUpload control in ASP.NET you can upload multiple images using javascript and store images in selected folder.

This only need Jquery.min.js and FileUpload control.

Screen shot:

1. Multiple Images Upload

2. Choose Mulitple images

2. Preview of Multiple Images


Here is the example:

Script Path

//Here is the open source jquery file
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>


Body

//Here is the source code of body

<body style="margin: 0px; padding: 0px;">
    <form id="form1" runat="server">
    <div align="center" style="width: 100%; height: auto; background-color: #cfcfcf;">
        <div style="width: 960px; height: auto;">
            <h1>
                Multiple image upload with preview by Manjunath Bilwar</h1>
            <div>
                <input type="file" id="choose" multiple="multiple" />
                <br>
                <div id="uploadPreview">
                </div>
            </div>
        </div>
    </div>

Script 

//Here is the javascript creating preview thumbnails of multiple images

    <script type="text/javascript">
        // var url = window.URL || window.webkitURL; // alternate use

        function readImage(file) {

            var reader = new FileReader();
            var image = new Image();

            reader.readAsDataURL(file);
            reader.onload = function(_file) {
                image.src = _file.target.result;              // url.createObjectURL(file);
                image.onload = function() {
                    var w = this.width,
                h = this.height,
                t = file.type,                           // ext only: // file.type.split('/')[1],
                n = file.name,
                s = ~ ~(file.size / 1024) + 'KB';
                    $('#uploadPreview').append('<img src="' + this.src + '"> ' + w + 'x' + h + ' ' + s + ' ' + t + ' ' + n + '<br>');
                };
                image.onerror = function() {
                    alert('Invalid file type: ' + file.type);
                };
            };

         }
        $("#choose").change(function(e) {
            if (this.disabled) return alert('File upload not supported!');
            var F = this.files;
            if (F && F[0]) for (var i = 0; i < F.length; i++) readImage(F[i]);
        });
   
    </script>

    </form>
</body>

 

Download Link

//Here you can download the simple demo project of Multiple Images upload

https://drive.google.com/file/d/0B7XVDU9gdC-lYTdHY2duRUMyNDQ/edit?usp=sharing 

If you have any query comment will be appreciated :)

Saturday, 21 December 2013

Styled Checkboxes with pure CSS that work upto IE5 and cross browser

 

Styled Checkboxes with pure CSS that work upto IE5 and cross browser

Styled checkboxes with pure CSS

The idea is that using the ':before' pseudo-class allows us to define the checkbox style in pure CSS, using the 'content' attribute to define the check symbol used and the ':checked' pseudo-selector to switch it. ':before' has to be on the subsequent element so that we can select it properly (you can't define ':before' for <input> elements).

IE 8 doesn't support ':checked' so we switch a class on it using jQuery and IE 6 & 7 don't support ':before' so we add a <span> to do its job.

IE fallbacks currently don't work! Feel free to suggest fixes :-) 

Demo

 

 

CSS

<style type="text/css">
.ckbox
{
width: 25px;
height: 25px;
}
.custom-checkbox
{
position: relative;
display: inline-block;
}

.custom-checkbox > .box
{
position: relative;
display: block;
width: 25px;
height: 25px;
background-color: #E5E5E5;
padding: 0px;
margin: 0px;
}

.custom-checkbox > .box > .tick
{
position: absolute;
left: 4px;
top: 7px;
width: 14px;
height: 6px;
border-bottom: 4px solid #000;
border-left: 4px solid #000;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
display: none;
}

.custom-checkbox > input:checked + .box > .tick
{
display: block;
}

.custom-checkbox > input
{
position: absolute;
outline: none;
left: 0;
top: 0;
padding: 0;
width: 25px;
height: 25px;
border: none;
margin: 0;
opacity: 0;
z-index: 1;
}

</style> 

Script

//Add jquery file

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>

//Checkbox Check click call the function

<script type="text/javascript">
  GetSelectedValue();
    function GetSelectedValue() {
    var final = '';

    $('.ckbox:checked').each(function() {

                var values = $(this).val();
                final += values + ",";       
     });
     alert(final);
}
</script>

HTML

 
<body>
 <form action="" method="GET">
  <table style="background-color: #E5E5E5;">
   <tr>
    <td>
      <span class="custom-checkbox">
      <input onclick="GetSelectedValue();" id="fileItem" name="fileItem"   type="checkbox" class="ckbox" value="1" checked="checked" />
      <span class="box" ><span class="tick"></span></span>
      </span>
      <input id="fileId" name="fileId" type="hidden" value="" />
    </td>
    <td>
      <label for="fileItem" title="">Check</label>

       <div class="custom-checkbox">
          chkChecked
       </div>
   </td>
  </tr>
  <tr>
   <td>
     <span class="custom-checkbox">
     <input onclick="GetSelectedValue();" id="fileItem1" name="fileItem1" type="checkbox" class="ckbox" value="2" />
     <span class="box" ><span class="tick"></span></span>
     </span>
     <input id="fileId" name="fileId" type="hidden" value="" />
  </td>
  <td>
    <label for="fileItem1" title="">Check</label>

   <div class="custom-checkbox">
     chkChecked
    </div>
   </td>
  </tr>
 </table>
</body>
 

Download Link

https://drive.google.com/file/d/0B7XVDU9gdC-lQnlUV2Fqc3BSYUU/edit?usp=sharing