Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : 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 December 12th, 2011, 04:20 PM
Authorized User
Points: 101, Level: 2
Points: 101, Level: 2 Points: 101, Level: 2 Points: 101, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 21
Thanks: 1
Thanked 1 Time in 1 Post
Default Page Methods (Ch 10, p 358)

When I click the button "SayHelloPageMethod" nothing happens. The Web Services button "SayHello" works fine.

I have compared my WebServices.aspx, NameService.vb, WebServices.aspx.vb and Frontend.master pages to those in the Source\Chapter 10 directory and cannot find any differences. (Both buttons work fine using the Source\Chapter 10 files.)

Where else should I look?
Reply With Quote
  #2 (permalink)  
Old December 12th, 2011, 06:40 PM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

If the buttons from my source work fine, there must be an error in yours.... ;-) Can you post the full code for the relevant pages? Please paste in Notepad first and then use the Code (#) button in this forum editor's toolbar to preserve formatting of the code.

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
  #3 (permalink)  
Old December 13th, 2011, 11:16 AM
Authorized User
Points: 101, Level: 2
Points: 101, Level: 2 Points: 101, Level: 2 Points: 101, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 21
Thanks: 1
Thanked 1 Time in 1 Post
Default Code for Page Method

WebServices.aspx.vb:
Code:
Imports System.Web.Services
Partial Class Demos_WebServices
  Inherits BasePage
  <WebMethod()>
  Public Shared Function HelloWorld(ByVal yourName As String) As String
    Return String.Format("Hello {0}", yourName)
  End Function
End Class

WebServices.aspx:
Code:
<%@ Page Title="Web Services Demo" Language="VB" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="WebServices.aspx.vb" Inherits="Demos_WebServices" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
  <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
  <Services>
    <asp:ServiceReference Path="~/WebServices/NameService.asmx" />
  </Services>
  </asp:ScriptManagerProxy>
  <input id="YourName" type="text" />
  <input id="SayHello" type="button" value="Say Hello" />
  <input id="SayHelloPageMethod" type="button" value="Say Hello with a Page Method" />
  <script type="text/javascript">
    function HelloWorld()
    {
      var yourName = $get('YourName').value;
      NameService.HelloWorld(yourName, HelloWorldCallBack);
    }

    function HelloWorldPageMethod()
    {
      var yourName = $get('YourName').value;
      PageMethods.HelloWorld(yourName, HelloWorldCallback);
    }

    function HelloWorldCallBack(result)
    {
      alert(result);
    }

    $addHandler($get('SayHello'), 'click', HelloWorld);

    $addHandler($get('SayHelloPageMethod'), 'click', HelloWorldPageMethod);
  </script>
</asp:Content>

Frontend.master:
Code:
<%@ Master Language="VB" CodeFile="Frontend.master.vb" Inherits="MasterPages_Frontend" %>

<!DOCTYPE html PUBLIC "-//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>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
    
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
    </asp:ScriptManager>
      <div id="PageWrapper">
        <div id="Header"><a href="~/" runat="server"></a></div>
        <div id="MenuWrapper">
          <asp:Menu ID="Menu1" runat="server" CssClass="MainMenu" 
            DataSourceID="SiteMapDataSource1" Orientation="Horizontal" 
            StaticEnableDefaultPopOutImage="False" BorderStyle="NotSet">
          </asp:Menu>
          <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" 
            ShowExpandCollapse="False">
          <LevelStyles>
            <asp:TreeNodeStyle CssClass="FirstLevelMenuItems" />
          </LevelStyles>
          </asp:TreeView>
          <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" 
            ShowStartingNode="False" />
        </div>
        <div id="MainContent">
          <asp:SiteMapPath ID="SiteMapPath1" runat="server">
          </asp:SiteMapPath><br /><br />
          <asp:ContentPlaceHolder ID="cpMainContent" runat="server">
            This is default text that shows up in content pages that don't
            explicitly override it.</asp:ContentPlaceHolder>
        </div>
        <div id="Sidebar">Select a Theme<br />
          <asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True">
            <asp:ListItem>Monochrome</asp:ListItem>
            <asp:ListItem>DarkGrey</asp:ListItem>
          </asp:DropDownList>
          <br />
          <br />
          <Wrox:Banner ID="Banner1" runat="server" DisplayDirection="Vertical" />
          <br />
        </div>
        <div id="Footer">Footer Goes Here</div>
      </div>
    </form>
</body>
</html>
Frontend.master.vb:
Code:
Partial Class MasterPages_Frontend
    Inherits System.Web.UI.MasterPage

  Protected Sub ThemeList_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ThemeList.SelectedIndexChanged
    Dim preferredTheme As HttpCookie = New HttpCookie("PreferredTheme")
    preferredTheme.Expires = DateTime.Now.AddMonths(3)
    preferredTheme.Value = ThemeList.SelectedValue
    Response.Cookies.Add(preferredTheme)
    Response.Redirect(Request.Url.ToString())
  End Sub


  Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
      Dim selectedTheme As String = Page.Theme
      Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
      If preferredTheme IsNot Nothing Then
        selectedTheme = preferredTheme.Value
      End If
      If Not String.IsNullOrEmpty(selectedTheme) AndAlso _
        ThemeList.Items.FindByValue(selectedTheme) IsNot Nothing Then
        ThemeList.Items.FindByValue(selectedTheme).Selected = True
      End If
    End If
    Select Case Page.Theme.ToLower()
      Case "darkgrey"
        Menu1.Visible = False
        TreeView1.Visible = True
      Case Else
        Menu1.Visible = True
        TreeView1.Visible = False
    End Select
  End Sub
End Class
NameService.asmx:
Code:
<%@ WebService Language="VB" CodeBehind="~/App_Code/NameService.vb" Class="NameService" %>
NameService.vb:
Code:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://www.jlransford.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class NameService
  Inherits System.Web.Services.WebService

  <WebMethod()> _
  Public Function HelloWorld(ByVal yourName As String) As String
    Return String.Format("Hello {0}", yourName)
  End Function

End Class
Reply With Quote
  #4 (permalink)  
Old December 16th, 2011, 08:58 AM
Imar's Avatar
Wrox Author
Points: 72,038, Level: 100
Points: 72,038, Level: 100 Points: 72,038, Level: 100 Points: 72,038, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,080
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Found it. In the code for the page method you spelled HelloWorldCallBack with a lower case b (e.g. HelloWorldCallback instead of HelloWorldCallBack). Change the lower case b to an upper case B and it should work.

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:
jlransford (December 16th, 2011)
  #5 (permalink)  
Old December 16th, 2011, 08:28 PM
Authorized User
Points: 101, Level: 2
Points: 101, Level: 2 Points: 101, Level: 2 Points: 101, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2010
Posts: 21
Thanks: 1
Thanked 1 Time in 1 Post
Default Page Method

Thanks, Imar! Give me Visual Basic, PLEASE!....
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
this-> pointers - (Page 358) Ivor Horton's book leogoldseed Visual C++ 2005 2 September 7th, 2010 04:26 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 01:20 PM.


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