Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 April 1st, 2010, 11:50 AM
Banned
 
Join Date: Jan 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
Default Chapter 10 -Function question restated

In Chapter 10 page 345 you enter the following code to call the method/function to return then name entered as a string. But this method has only one argument. How can you specifiy "HelloWorldCallback" as a second argument? I understand what it does, but it doesn't follow the syntax rules. How would I know that the HelloWorld method I wrote could handle another argument and how would I know that this argument is another method and not a paramerter that is used in MY HelloWorld function?
If this can't be answered in this forum, can you direct me to a forum that can?

Thanks,

Chuck

Java script in NameService.vb
Code:
  <WebMethod()> _
  Public Function HelloWorld(ByVal yourName As String) As String
    Return String.Format("Hello {0}", yourName)
  End Function
VB code in WebService.aspx
Code:
NameService.HelloWorld(yourName, HelloWorldCallback);
 
Old April 2nd, 2010, 03:31 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Chuck,

The Web Service method is *always* called with one parameter. A strongly typed language such as C# or VB doesn't allow you to pass in less or fewer arguments (unless they are optional which isn't the case in this method).

However, the call to the web service is not a direct call. It's a call to the AJAX framework that in turn calls the web service for you. The code you're using is JavaScript which does allow you to pass more or fewer arguments. To see what you need to pass, look at IntelliSense. Place your cursor after the opening parenthesis after NameService.HelloWorld and press Ctrl+Space. You get a tooltip that tells you you can pass:

1. string yourName
2. onSuccess
3. onFailed
4. userContext

yourName is the parameter defined in the web service method and is required because it's needed in the server side Web Service method. As explained in the book, onSuccess and onFailed are pointers to methods that can be run when the web service succeeds or fails. The userContext is also optional and enables you to pass information from the calling code to the success or failure handlers, in case you need to pass around client state from the original code to the success or failure handlers.

For more info: http://msdn.microsoft.com/en-us/library/bb398995.aspx

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 2nd, 2010, 03:38 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

BTW:
Quote:
Last edited by ChuckASP : Yesterday at 05:33 PM. Reason: No answers
I was away for the past couple of days so I couldn't respond earlier.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10 HelloWorld function ChuckASP BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 April 2nd, 2010 03:39 PM
Chapter 10 Try it Out (Page 328) IDE Question: jsymons BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 September 9th, 2009 03:06 PM
Another chapter 10 question. czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 4 April 3rd, 2005 09:12 PM
Question on chapter 10 - overriding RobMeade BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 4 August 12th, 2004 11:56 AM





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