Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2008, 03:59 PM
Authorized User
 
Join Date: Jul 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in understannding some javascript code

<script type="text/javascript">
   function CallUpdateProgress()
   {
      <asp:Literal runat="server" ID="lblScriptName" />;
   }

   function UpdateProgress(result, context)
   {
      // result is a semicolon-separated list of values, so split it
      var params = result.split(";");
      var percentage = params[0];
      var sentMails = params[1];
      var totalMails = params[2];

      if (totalMails < 0)
         totalMails = '???';

      // update progressbar's width and description text
      var progBar = window.document.getElementById('progressbar');
      progBar.style.width = percentage + '%';
      var descr = window.document.getElementById('progressdescriptio n');
      descr.innerHTML = '<b>' + percentage + '% completed</b> - ' +
         sentMails + ' out of ' + totalMails + ' e-mails have been sent.';

      // if the current percentage is less than 100%,
      // recall the server callback method in 2 seconds
      if (percentage == '100')
         window.document.getElementById('panelcomplete').st yle.display = '';
      else
         setTimeout('CallUpdateProgress()', 2000);
   }
</script>

This above mentioned javascript code is written in the code-behind file of SendingNewsletter.aspx page. While newsletters are being send, this code gets the calculated values of different progress variables and shows a progress information (of sending operation) on the same page. There is a check in this code i.e.
if(totalMails < 0)
   totalMails='???'
I know that the totalMails variable is less than zero in only two cases (if there is any other case, plz let me know)
1. If no user subscribe for newsletter.
2. If the variable's value is wrongly calculated.

Now, the thing which i want to know is that if this check becomes true then why we are storing '???' this in an integer variable named totalMails and after storing this string or value how the rest of the operation proceeds.

In short, i just want to know the logic behind storing this '???' and its consequences.

 
Old January 17th, 2008, 07:06 PM
Authorized User
 
Join Date: Jul 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If anybody knows....Please.....Do reply this, its urgent....!!!

 
Old January 18th, 2008, 05:46 AM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

Don't worry about ??? because, it is just place holder and, javascript will take care of converting number to string.

Even if totalmail is a number then, it is being converted to string in that message(sentMails + ' out of ' + totalMails + ' e-mails have been sent.).

So you can change ??? to anything you want.

urt
 
Old January 18th, 2008, 05:02 PM
Authorized User
 
Join Date: Jul 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx for replying, but it doesn't solve my confusion ...!!!

if (totalMails < 0)
         totalMails = '???';

If this check becomes true, why we need to store this ??? in totalMails variable. As i wrote before that totalMails is less than zero in two cases
1. If no user subscribe for newsletter.
2. If the variable's value is wrongly calculated or an error occurs while calculating the value of this value.

Now in first case it should simply display a message "no user subscribe for newsletter".
And in second case, it should try again (some predefined attempts) and calculate the totalMails value untill it gets a value greater than zero.Or if it fails to do so then it should display "unable to figureout, that how many user/s subscribe for newsletter" (or some other message that defines the problem).

For checking out the first case, i edit all of the registered users profiles and modify them as "No Subscription for newsletter". After then i send a newsletter, but the message on my site's sendingnewsletter page was

Sending Newsletter...

0% completed - 0 out of 0 e-mails have been sent.

I wait for more then 10 minutes but the same message apperas on the screen with empty progress bar. I mean that it should give some real feed back (the purpose for which we write this javescript code) but it wasn't giving any feedback and it seems like application is being struck.

You said it is just a place holder and the javescript itself converst the number to string. Conversion it userfull when we have some number of subscribers and we want to **************** the progress information i.e. 50% completed - 20 out of 40 e-mails have been sent.But here in this case when the check becomes true, what is the use of this place holder and how the further code proceed.







Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript code popuri_krishna Javascript How-To 0 May 23rd, 2007 11:58 PM
problems with JavaScript Code red_fiesta Javascript 5 March 6th, 2007 04:44 PM
javascript as well as codebehind code k.manisha .NET Framework 1.x 0 November 24th, 2006 04:23 AM
using javaScript in the code behind @shish ASP.NET 1.0 and 1.1 Basics 1 April 10th, 2006 03:19 PM
JavaScript Code problem Ben Horne Javascript 5 February 11th, 2006 02:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.