Click here to Skip to main content
15,884,298 members
Articles / Programming Languages / C#

Use jQuery Progressbar To Display The Percentage Of User Info

Rate me:
Please Sign up or sign in to vote.
4.33/5 (3 votes)
26 Dec 2011CPOL2 min read 28.1K   17   2
This article explains the function and the use of Progressbar

The original: http://zoyobar.blogspot.com/2011/12/use-jquery-progressbar-to-display-user.html

Introduction/Catalog

Due to the limited time, synchronization cannot be guaranteed in more than one blog article, at the following address you can view up-to-date content, please understand:

http://zoyobar.blogspot.com/2011/12/use-jquery-progressbar-to-display-user.html

Please download the sample code at the section JQueryElement Demo Download of Download JQueryElement, the directory is /progressbar/Default.aspx.

This article explains the function and the use of Progressbar , the catalog is as follows:

* Prepare
* Progress
* Appendix: The Percentage Of Information

Prepare

Be sure that you have got the latest version of JQueryElement at the section JQueryElement.dll Download of Download JQueryElement

Use the following statements to reference namespace:

<%@ Register Assembly="zoyobar.shared.panzer.JQueryElement"
 Namespace="zoyobar.shared.panzer.ui.jqueryui"
 TagPrefix="je" %>
<%@ Register Assembly="zoyobar.shared.panzer.JQueryElement"
 Namespace="zoyobar.shared.panzer.web.jqueryui"
 TagPrefix="je" %>

In addition to the namespace, you need to reference the jQueryUI scripts and styles, there is a custom theme for jQueryUI in the compressed file downloaded at the section JQueryElement.dll Download of Download JQueryElement, if you need more themes, you can get them at jqueryui.com/download:

<link type="text/css" rel="stylesheet"
 href="[style path]/jquery-ui-<version>.custom.css" />
<script type="text/javascript"
 src="[script path]/jquery-<version>.min.js"></script>
<script type="text/javascript"
 src="[script path]/jquery-ui-<version>.custom.min.js"></script>

Progress

Through the property Value to initialize the progress, Value should be between 0 and 100.

You can also use javascript on the client to set or get the progress, more information please refer to docs.jquery.com/UI/Progressbar:

<je:Progressbar ID="pb" runat="server" ScriptPackageID="package"
 CssClass="info-bar" IsVariable="true">
</je:Progressbar>

<script type="text/javascript">
 $(function () {
  var p = progressbar('option', 'value');
  p += 20;

  pb.progressbar('option', 'value', p);
 });
</script>

In the above example, set the IsVariable property of Progressbar to true, it'll generate a javascript variable named pb. You can use pb to get and set the progress of progressbar.

Appendix: The Percentage Of Information

In this section, we use Progressbar to show the percentage of user information:

<je:Progressbar ID="pb" runat="server" ScriptPackageID="package" Value="20">
</je:Progressbar>

...

<je:ScriptPackage ID="package" runat="server" />

Here is a progress bar, its corresponding javascript will be generated in the ScriptPackage control which the ID is package.

After the page loads, it'll call the method init that generated by AjaxManager:

<je:AjaxManager ID="ajax" runat="server">
 <je:AjaxSetting ClientFunction="init" Url="userinfo1.ashx" Success="
  function(data){
   $('#prec').text(-:data.prec + '%');
   pb.progressbar('option', 'value', -:data.prec);

   $('#realname').val(-:data.realname);
   $('#nickname').val(-:data.nickname);
   $('#email').val(-:data.email);
   $('#sex').val(-:data.sex);
   $('#birthday').val(-:data.birthday);
  }
  ">
  <je:Parameter Name="c" Type="Expression" Value="'get'" />
 </je:AjaxSetting>
</je:AjaxManager>

...

<script type="text/javascript">
 $(function () {
  init();
 });
</script>

The role of init method is to get user information from the userinfo1.ashx, and the information will be displayed on the page. For more AjaxManager information, please refer to Use AjaxManager To Generate javascript That Calls The Server-Side Method.

In the above code, -:data will be replaced by data or data.d based on different .NET version, more information, please refer to Return JSON In Different .NET Version.

Finally, we need a save button:

<je:Button ID="cmdSave" runat="server" ScriptPackageID="package"
 Label="You can always save">
 <ClickAsync Url="userinfo1.ashx" Success="
 function(data){
  $('#prec').text(-:data.prec + '%');
  pb.progressbar('option', 'value', -:data.prec);

  alert('ok');
 }
 ">
  <je:Parameter Name="c" Type="Expression" Value="'save'" />
  <je:Parameter Name="realname" Type="Selector" Value="'#realname'" />
  <je:Parameter Name="nickname" Type="Selector" Value="'#nickname'" />
  <je:Parameter Name="email" Type="Selector" Value="'#email'" />
  <je:Parameter Name="sex" Type="Selector" Value="'#sex'" />
  <je:Parameter Name="birthday" Type="Selector" Value="'#birthday'" />
 </ClickAsync>
</je:Button>

When you click on the button, user information on the pages will be passed to userinfo1.ashx, userinfo1.ashx will return the percentage of information.

In AjaxManager and the ClickAsync property of Button, we use the Parameter to increase the parameter, more information can refer to Through Parameter Object Add Ajax Request Parameter.

Revision History

Return JSON In Different .NET Version
Use AjaxManager To Generate javascript That Calls The Server-Side Method
Through Parameter Object Add Ajax Request Parameter

This article was originally posted at http://zoyobar.blogspot.com/feeds/posts/default?alt=rss

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalmy vote of 4 Pin
Uday P.Singh30-Dec-11 5:46
Uday P.Singh30-Dec-11 5:46 
GeneralMy vote of 5 Pin
Abinash Bishoyi27-Dec-11 1:32
Abinash Bishoyi27-Dec-11 1:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.