Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 18th, 2014, 10:39 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Ch 10 and Page Methods

Hi Imar,

Please just ignore this question if too far off-topic.

I've been reviewing ch 10 and page methods as a way to create a scaled down version of my site using jQuery Mobile. I set up a bare bones jQuery Mobile
page with this book but implemented it as an aspx page so I could follow your example. I integrated your example with the mobile example and this bare bones version seems to work fine in my development environment. This approach will allow me to reuse EF-linq-vb from my regular desktop site. I should note that my desktop version runs on a smartphone but it's just not very user friendly for someone who pulls out their phone on a bicycle ride just to get some basic information about one of my routes.

So, it seems that if I use an aspx page, I can use the page method as you describe and move forward learning about the UI aspects of jQuery Mobile and not worry about how I'm going to access my DB data. However, I've not found an example for this marriage and I wonder if 3 weeks from now I'll discover this was a very bad strategy. I know you don't cover mobile in your book, but I suspect you know if this overall approach is OK or not.

Here is the VB:

Code:
Imports System.Web.Services
Partial Class TestMobileVB
    Inherits System.Web.UI.Page
    <WebMethod()>
    Public Shared Function HelloWorld(name As String) As String
        Return String.Format("Hello {0}", name)
    End Function
End Class
And the markup:

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="TestMobileVB.aspx.vb" Inherits="TestMobileVB" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
     <meta name="viewport" content="width=device-width, initial-scale=1, 
         maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
    <link rel="stylesheet" href="css/custom.css" />
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script src="js/custom-scripting.js"></script>
    <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
    <title>Boilerplate</title> 
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">  </asp:ScriptManager>
        <div>
            <div data-role="page">
                <div data-role="header">
                    <h1>Boilerplate</h1>
                </div>
                <div data-role="content">
                    <p>Page Body content</p>
                     <div>
                        <input id="YourName" type="text" />
                        <input id="SayHelloPageMethod" type="button" value="Say Hello with a Page Method" onclick="helloWorldPageMethod();" />
                        <span id="vbdata"></span>
                    </div>
                </div>
                <div data-role="footer">
                    <h4>Footer content</h4>
                </div>
                <a href="{dynamic location}" class="fullSiteLink">View Full Site</a>
            </div>
        </div>
        <script type="text/javascript">
            function helloWorldPageMethod() {
                var yourName = document.getElementById('YourName').value;
                PageMethods.HelloWorld(yourName, helloWorldCallback);
            }
            function helloWorldCallback(result) {
                $("#vbdata").text(result);
                //alert(result);
            }
        </script>
    </form>
</body>
</html>
As I mentioned, if this is too far off topic to answer, I understand.
Reply With Quote
  #2 (permalink)  
Old January 19th, 2014, 08:28 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

In general, the ASP.NET team recommends to stop using Page Methods. There are some compatibility issues with frameworks like FriendlyUrls (which are enabled by default in new ASP.NET 4.5.1. web sites using VS 2013).

I would look into Web API instead, as it's designed for exactly this purpose. You can learn more about Web API here: http://www.asp.net/web-api

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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
daveharney (January 19th, 2014)
  #3 (permalink)  
Old January 19th, 2014, 02:46 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Good Strategy

Hi Imar,

Many thanks -I knew you could put me on the right path! I did the example and it worked fine. The web page is simple html with jQuery - so this should work very well with jQuery Mobile - and I very much like jQuery. My challenge is going to be recreating this tutorial in VB so I can reuse lots of my existing VB code. You are one of the few authors that gives VB much love. Had I realized that Microsoft was going to treat VB like a second class citizen I would have used C# from the beginning of my project. At the time, Microsoft was loudly proclaiming that there was no need to chose one language over the other - just use what is most familiar. I liked VB for a variety of reasons so that's the route I took. Now, VB.NET tutorials and examples are scarce as hen's teeth if anything remotely new is involved.
Reply With Quote
  #4 (permalink)  
Old January 21st, 2014, 10:50 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Web API and Hosting Service

I tried not to bother you with this but I'm stuck again. The Web API seems to be the perfect solution for my jQuery Mobile project. But, I want to do a little "proof of concept" before I get to far into the weeds of the UI part. So, I did the VB conversion (worked fine) and moved the project code to my WinHost site - you can see the current version of it here. If you enter the number "2" you should get back "yy". However, the Web API call fails (Not Found) - although it worked perfectly on my development PC. I posted a question about this on Stack Overflow but received no suggestions. It seems that the URI line in the tutorial code might be the key to this:
Code:
var uri = 'api/class1s';
As this also works:
Code:
var uri = 'http://localhost:12345/api/class1s';
This is currently what is on the hosting service - in the folder that contains the project:
Code:
var uri = 'http://www.bikex.net/mobile/api/class1s';
It's not clear if this is just a matter of getting that "var uri" correct by adding my URL properly or if some web config issue needs to be fixed. Or, if I need to submit a service ticket to WinHost for some change on their end to allow this type of api. I've spent a lot of time googling this but most of the advice seems to center on "self hosting" and get's to be pretty complicated.

Any guidance much appreciated.
Reply With Quote
  #5 (permalink)  
Old January 22nd, 2014, 04:07 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Since this deals with Web API, this is getting out of scope for me this forum category that relates to my book. For future questions related to this, find a Web API or a general .NET forum category here at p2p.wrox.com.

That said, when you install Web API, you also get a bunch of other stuff added to your site / project, such as code in Global.asax and files in the Bin folder. Did you deploy those to the server as well? Looks like you haven't as the URL isn't caught by Web API which seems to imply that Web API routing hasn't kicked in.

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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
daveharney (January 22nd, 2014)
  #6 (permalink)  
Old January 22nd, 2014, 10:39 AM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default The Extra Mile

Hi Imar,

I understand the need to stay within the scope of the book and I very much appreciate your going beyond that scope to give me some direction. I'll look for another author here (or let me know if you recommend someone).

I had moved all the files in the project via FTP and also tried the "publish" method just to see if that made a difference - it didn't.

Thanks again and looking forward to your new book.
Reply With Quote
  #7 (permalink)  
Old January 22nd, 2014, 12:12 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Also, make sure your routes match the current location. Is your API really in the sub folder Mobile?

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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
daveharney (January 22nd, 2014)
  #8 (permalink)  
Old January 22nd, 2014, 01:03 PM
Authorized User
Points: 353, Level: 6
Points: 353, Level: 6 Points: 353, Level: 6 Points: 353, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2011
Posts: 86
Thanks: 20
Thanked 3 Times in 3 Posts
Default Humbled

Hi Imar,

Thanks again for thinking about this. I guess the technical term for what happened is officially called a "brain f**t". I'm totally embarrassed to have to admit that I simply forgot to use the WinHost tool to mark the folder as an ASP.NET "Application Starting Point". Because the starting web page is an html page, I was ignoring the fact that VB part is still and ASP.NET application and still needs to have the folder designed for this purpose.

So, your original suggestion to use the Web API technology is still the best piece of advice I've received. You can check the fixed version of my little test here. Enter a 1, 2, or 3 and click "Search" - you should see xx, yy, or zz below the search box.

Last edited by daveharney; January 22nd, 2014 at 06:45 PM..
Reply With Quote
  #9 (permalink)  
Old January 25th, 2014, 06:20 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Excellent. good to hear it's working.

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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Methods (Ch 10, p 358) jlransford BOOK: Beginning ASP.NET 4 : in C# and VB 4 December 16th, 2011 08:28 PM
Page Methods TeaDrinkingGeek BOOK: Beginning ASP.NET 4 : in C# and VB 2 March 7th, 2011 07:05 AM
Ch. 10: UpdatePanel makes page disappear JohnInPomeroy BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 1st, 2010 04:20 PM
C# Ch 10 Page 362 surefire BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 5 February 25th, 2008 01:55 PM
C# Ch 10 Page 370 - Simple User Control surefire BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 4 February 25th, 2008 01:53 PM



All times are GMT -4. The time now is 10:06 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.