Showing posts with label JQuery. Show all posts
Showing posts with label JQuery. Show all posts

How to check download speed in asp.net


Description:-

In this article I will explain how to check and find the Internet Connection (Download) speed using C#. A file of known size will be downloaded from a remote server 5-10 times and the time required to download the file is noted. Finally the average of these readings will be used to calculate approximate Internet Connection or Download speed. For more accurate readings, you need to download larger files.

I am downloading a jQuery script file from Google CDN. The size of the file is 261 KB, which I have determined from windows explorer. The download speed of calculated by dividing the size of the file (in KB) with the difference in download start and end time (in seconds).

The above process is repeated 5 times and the result is stored in an array after each iteration. Follow given code to check your internet connection speed (download speed).

Default.aspx:-
<div>
  <asp:Label ID="lblDownloadSpeed" runat="server" />
  <asp:Button ID="Button1" Text="Check Speed" runat="server" OnClick="CheckSpeed" />
</div>

Step 2: Now Call a JavaScript in your webPage

<script type="text/javascript" src="Scripts/advajax.js"></script>

Step 3: Now generate Button Click event to Create Code for Check Download Speed.

Default.aspx.cs:-
protected void CheckSpeed(object sender, EventArgs e)
{
   double[] speeds = new double[5];
   for (int i = 0; i < 5; i++)
   {
      intjQueryFileSize = 261; //Size of File in KB.
      WebClient client = new WebClient();
      DateTime startTime = DateTime.Now;
      client.DownloadFile("http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js", Server.MapPath("~/jQuery.js"));
      DateTime endTime = DateTime.Now;
      speeds[i] = Math.Round((jQueryFileSize / (endTime - startTime).TotalSeconds));
   }
   lblDownloadSpeed.Text = string.Format("Download Speed: {0}KB/s", speeds.Average());
}

NameSpaces:-

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Linq;

Step 4: Now run you WebPage.
Step 5: Click on CheckSpeed button to Check Download Speed.

How to Create AutoUpload File Using Jquery in Asp.Net


Description:-

In this Example we will Create Auto Upload file using JQuery in Dot net. Browse file and Upload Directly with Specify Folder. Here we will Create Script for Browse File and Upload Directly. Using Uplodify JQuery we can achieve this functionality.

Drag and Drop FileUpload Control in your Webpage.

<div style="padding: 40px">
  <asp:FileUpload ID="FileUpload1" runat="server" />
</div>

We will User JQuery in this Webpage is given below.

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.uploadify.js"></script>
Now Create Script for Auto Upload after Selecting File with Some Property like Auto Upload, Multi Select File, and Folder for Save Image, Image Extension for Validation, Files Description, and Button Text for Browse files etc...

<script type="text/javascript">
    $(window).load(
    function () {
        $("#<%=FileUpload1.ClientID %>").fileUpload({
            'uploader': 'scripts/uploader.swf',
            'cancelImg': 'images/cancel.png',
            'buttonText': 'Browse Files',
            'script': 'Upload.ashx',
            'folder': 'Files',
            'fileDesc': 'Image Files',
            'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
            'multi': true,
            'auto': true
        });
    }
);
</script>

Now run your Application and Browser File it will Auto Upload your Selected File in your Selected Folder.
create JQuery ui tabs content navigation in asp.net

create JQuery ui tabs content navigation in asp.net

Description:-

In this Example we explain that how to create JQuery UI tabs content navigation in your asp.net Website or create Tab control in asp.net using JQuery.

We all know or show that the One of the most features that you may often see in the many websites is the tabs-based content navigation. For example one tab contain Register form second tab contain Login form etc…

We can also create UI tab using Ajaxcontrol Toolkit but this is the client side UI tab using JQuery and also reduce the load and does not Postback but in Ajax we also require whole toolkit in our project so JQuery is the best way to dynamically create JQuery UI tab in asp.net.

Default.aspx:-

<!DOCTYPE htmlPUBLIC"-//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></title>
  <link type="text/css"href="http://ajax.microsoft.com/ajax/jquery.ui/1.8.9/themes/blitzer/jquery-ui.css" rel="Stylesheet"/>
  <script type="text/javascript"src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.js"></script>
  <script type="text/javascript"src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.min.js"></script>
  <script type="text/javascript">
     $(function () {
        $("#InfoTab").tabs();
     });
  </script>
</head>
<body>
<form id="form1" runat="server">
<div>
  <div class="content">
    <div id="InfoTab" style="width:500px;">
      <ul>
        <li><a href="#Jignesh">Umesh Patel</a></li>
        <li><a href="#pintu">Chirag Patel</a></li>
        <li><a href="#rahul">Kiran Patel</a></li>
      </ul>
      <div id="Umesh">
        <p> Umesh Patel is a sofware engineer and he is worked on .Net technology. he was completed his post gradution with MCA in Rajkot and he is also a Blogger.
        </p>
      </div>
      <div id="Chirag">
        <p>Chirag Patel is a sofware engineer and he is worked on .Net technology. he was completed his post gradution with MCA in Rajkot and he is also a businessman..
        <br/>
        </p>
      </div>
      <div id="Kiran">
        <p>Kiran Patel is a sofware engineer and he is worked on .Net technology. he was completed his post gradution with MCA in Rajkot and he is also a Blogger.
        </p>
      </div>
    </div>
  </div>
</div>
</form>
</body>
</html>

How to Create Scrollable Gridview in Asp.Net Using JavaScript


Description:-

In this example we will see how to create scrollable GridView in dot net using JQuery. Here bind Gridview from SQL Server and Fixed size we will assign for Gridview for Particular area so we can set Scroll in Gridview. Let’s start how to do it.

In you webpage Design your Gridview like below and create script for scrolling. Using Data Fields we can Retrieve Column Data from SQL Server.

Download File:- ScrollableGridPlugin.js, Jquery-1.4.1.min.js

Default.aspx:-

<div>
  <asp:GridView ID="fixedHeaderScrollableGridView" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
  DataKeyNames="ProductID" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" 
  ForeColor="Black" GridLines="Vertical" >
  <AlternatingRowStyle BackColor="#CCCCCC" />
  <Columns>
    <asp:BoundField DataField="ProductID" HeaderText="ProductID" />
    <asp:BoundField DataField="ProductName" HeaderText="ProductName" />
    <asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" />
    <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" />
    <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" />
  </Columns>
  <FooterStyle BackColor="#CCCCCC" />
  <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
  <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
  <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
  <SortedAscendingCellStyle BackColor="#F1F1F1" />
  <SortedAscendingHeaderStyle BackColor="#808080" />
  <SortedDescendingCellStyle BackColor="#CAC9C9" />
  <SortedDescendingHeaderStyle BackColor="#383838" />
 </asp:GridView>
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString=
    "<%$ ConnectionStrings:DBCS %>" SelectCommand="SELECT * FROM [Products]"> </asp:SqlDataSource>
</div> 

Script for generating Gridview
<script src="jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="ScrollableGridPlugin.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
  $('#<%=fixedHeaderScrollableGridView.ClientID %>').Scrollable({ScrollHeight: 100});
  });
</script> 

Using ScrollableGridPlugin.js and Jquery-1.4.1.min.js you can create your Own Scrollable Gridview in browser and for giving Height you can assign limited height for Gridview.

In your Webpage Bind Gridview from SQL DataSource and Get data from SQL Database. Now Generate Script for Scrolling so we can Create Scroll in Gridview. For Connection String you Can Check your Web.config file. Here I have took my connection String for taking data from my Database. You can create our own when you bind connection string using SqlDataSource.

Now run your Webpage in Browser and you will get scroll in your Gridview.

Create World map using javascript in asp.net


Description:-

in this article we will create world map using fusionchart. here i have created simple world map using JSFiddle. using jquery we can craete it and display world map in html control. here is the demo example to create world map.

Download Files:- Fusionchart.js, Fusioncharts.maps.js, Fusioncharts.theme.fint.js,                                   Fusioncharts.world.js

Default.aspx:-

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
  <script src="JS/fusioncharts.js"type="text/javascript"></script>
  <script src="JS/fusioncharts.maps.js"type="text/javascript"></script>
  <script src="JS/fusioncharts.theme.fint.js"type="text/javascript"></script>
  <script src="JS/fusioncharts.world.js"type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
  <asp:Literal ID="lt" runat="server"></asp:Literal>
  <div id="chart-container">Charts will render here</div>
</div>
</form>
</body>
</html>

Default.aspx.cs:-


protected void Page_Load(object sender, EventArgs e)
{
  StringBuilder str = new StringBuilder();
  try
  {
    str.Append(@" <script type='text/javascript'>
    FusionCharts.ready(function () {
      varworldMap = new FusionCharts({
      type: 'world',
      renderAt: 'chart-container',
      width: '600',
      height: '400',
      dataFormat: 'json',
      dataSource: {" + Environment.NewLine);
      str.Append("\"chart\":{ " + Environment.NewLine);
      str.Append("\"theme\": \"fint\"" + Environment.NewLine);
      str.Append("}" + Environment.NewLine);
      str.Append("}" + Environment.NewLine);
      str.Append("}).render();" + Environment.NewLine);
      str.Append("});" + Environment.NewLine);
      str.Append("</script>");

      lt.Text = str.ToString();
  }
  catch (Exception ex)
  { }
}

Piechart using javascript and jquery from database in asp.net


Description:-

A pie chart that is rendered within the browser using SVG or VML. Displays tooltips when hovering over slices.

Making a 3D Pie Chart

If you set the is3D option to true, your pie chart will be drawn as though it has three dimensions:
is3D is false by default, so here we explicitly set it to true:

Making a Donut Chart

A donut chart is a pie chart with a hole in the center. You can create donut charts with the pieHole option:
The pieHole option should be set to a number between 0 and 1, corresponding to the ratio of radii between the hole and the chart. Numbers between 0.4 and 0.6 will look best on most charts. Values equal to or greater than 1 will be ignored, and a value of 0 will completely shut your piehole.
You can't combine the pieHole and is3D options; if you do, pieHole will be ignored.
Note that Google Charts tries to place the label as close to the center of the slice as possible. If you have a donut chart with just one slice, the center of the slice may fall into the donut hole. In that case, change the color of the label:

Rotating a Pie Chart

By default, pie charts begin with the left edge of the first slice pointing straight up. You can change that with the pieStartAngle option:
Here, we rotate the chart clockwise 100 degrees with an option of pieStartAngle: 100. (So chosen because that particular angle happens to make the "Italian" label fit inside the slice.)

Exploding a Slice

You can separate pie slices from the rest of the chart with the offset property of the slices option:
To separate a slice, create a slices object and assign the appropriate slice number an offset between 0 and 1. Below, we assign progressively larger offsets to slices 4 (Gujarati), 12 (Marathi), 14 (Oriya), and 15 (Punjabi):

Removing Slices

To omit a slice, change the color to 'transparent':
We also used the pieStartAngle to rotate the chart 135 degrees, pieSliceText to remove the text from the slices, and tooltip.trigger to disable tooltips:

Slice Visibility Threshold

You can set a value as the threshold for a pie slice to render individually. This value corresponds to a fraction of the chart (with the whole chart being of value 1). To set this threshold as a percentage of the whole, divide the percentage desired by 100 (for a 20% threshold, the value would be 0.2).
sliceVisibilityThreshold: 5/8 // This is equivalent to 0.625 or 62.5% of the chart.
Any slices smaller than this threshold will be combined into a single "Other" slice, and will have the combined value of all slices below the threshold.

Download Files:- Jquery.min.js, jsapi.js
Loading:-

The google.charts.load package name is "corechart".

 google.charts.load("current",{packages:["corechart"]});

The visualization's class name is google.visualization.PieChart.

var visualization = newgoogle.visualization.PieChart(container);

Create Table:-

CREATETABLE [dbo].[Suppliers](
                [ID] [int] NOTNULL,
                [CompanyName] [nvarchar](50)NOTNULL,
                [Total Suppliers] [nvarchar](50)NOTNULL,
                [Country] [nvarchar](50)NOTNULL,
                [Popularity] [int] NULL
)ON [PRIMARY]

GO

Default.aspx:-

<!DOCTYPEhtmlPUBLIC"-//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>Pie CHart</title>
<script src="JS/jquery.min.js" type="text/javascript"></script>
<script src="JS/jsapi.js" type="text/javascript"></script>
<script type="text/javascript">
  google.load('visualization', '1', { packages: ['corechart'] });
</script>
<script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json',
                    url: 'Chart.aspx/GetData',
                    data: '{}',
                    success:
                    function (response) {
                        drawVisualization(response.d);
                    }
                  });
             })
    function drawVisualization(dataValues) {
      var data = newgoogle.visualization.DataTable();
      data.addColumn('string', 'Column Name');
      data.addColumn('number', 'Column Value');

      for (vari = 0; i<dataValues.length; i++) {
          data.addRow([dataValues[i].ColumnName, dataValues[i].Value]);
        }

      new google.visualization.PieChart(document.getElementById('visualization')).
      draw(data, { title: "Totals Suppliers Chart" });
      }
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
    <div id="visualization" style="width: 600px; height: 350px;"></div>
</div>
</form>
</body>
</html>

Default.aspx.cs:-

[WebMethod]
public static List<Data>GetData()
{
  SqlConnection conn = new SqlConnection("ConnectionString");
  DataSet ds = new DataSet();
  DataTable dt = newDataTable();
  conn.Open();
  string cmdstr = "select top 5 Country, COUNT(CompanyName) [Total Suppliers] from [Suppliers] group by Country";
  SqlCommand cmd = new SqlCommand(cmdstr, conn);
  SqlDataAdapter adp = new SqlDataAdapter(cmd);
  adp.Fill(ds);
  dt = ds.Tables[0];
  List<Data> dataList = new List<Data>();
  string cat = "";
  int val = 0;
  foreach (DataRow dr in dt.Rows)
  {
    cat = dr[0].ToString();
    val = Convert.ToInt32(dr[1]);
    dataList.Add(newData(cat, val));
  }
  return dataList;
}

public class Data
{
  public string ColumnName = "";
  public int Value = 0;

  public Data(string columnName, int value)
  {
    ColumnName = columnName;
    Value = value;
  }
}

NameSpaces:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;

Fixed Sidebar during Scrolling between Header & Footer using jQuery in asp.net

Description:-

It explains How to create a sidebar or section that follows you as you scroll down the page. It is very useful to show special or important content to user.

HTML:-

<div id="wrapper">
<div id="header">...</div>
<div id="contentHolder">
<div class="leftsidebar">...</div>
<div class="content">...</div>
</div>
<div id="footer">...</div>
</div>

The main objective is to create fixed leftsidebar during scrolling between header and footer.

CSS:-

<style type="text/css">
#wrapper{margin: 0auto;width: 1000px; }
#contentHolder{position: relative;}
#header, #footer
{
  background: nonerepeatscroll00#CCFFFF;
  color: #000000;
  height: 80px;
  width: 1000px;
  clear: both;
  font-size: 3em;
  text-align: center;
  padding-top: 20px;
}
.leftsidebar
{
  background: nonerepeatscroll00#FFFFFF;
  border-color: #CCCCCC#BBBBBB#888888;
  border-style: solid;
  border-width: 1px2px2px1px;
  margin-bottom: 3px;
  position: absolute;
  top: 0;
  width: 160px;
}
.leftsidebarfixed
{
  position: fixed;
  top: 0;
}
.content
{
  float: left;
  margin-left: 165px;
  position: relative;
  width: 570px;
}
</style>

jQuery:-

$(function () {
var msie6 = $.browser == 'msie'&& $.browser.version< 7;
if (!msie6 && $('.leftsidebar').offset() != null) {
var top = $('.leftsidebar').offset().top - parseFloat($('.leftsidebar').css('margin-top').replace(/auto/, 0));
var height = $('.leftsidebar').height();
varwinHeight = $(window).height();
varfooterTop = $('#footer').offset().top - parseFloat($('#footer').css('margin-top').replace(/auto/, 0));
var gap = 7;
                $(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();

// whether that's below the form
if (y + winHeight>= top + height + gap && y + winHeight<= footerTop) {
// if so, ad the fixed class
                        $('.leftsidebar').addClass('leftsidebarfixed').css('top', winHeight - height - gap + 'px');
                    }
elseif (y + winHeight>footerTop) {
// if so, ad the fixed class
                        $('.leftsidebar').addClass('leftsidebarfixed').css('top', footerTop - height - y - gap + 'px');
                    }
else {
// otherwise remove it
                        $('.leftsidebar').removeClass('leftsidebarfixed').css('top', '0px');
                    }
                });
            }
        });