title: How to use Public Shared Sub to call functionality found in a Protected Sub goToRequestedPage() in Visual Basic
body: <p>Here is my issue: </p>
  
  <p>I have used the Javascript #Next 'on click' function to call the <code>Public Shared Sub NextPage()</code> method and also render my bookviewer in the "If-else" statement. </p>
  
  <p>However, I now need the <code>Public Shared Sub NextPage()</code> method to call <code>Protected Sub goToRequestedPage()</code>. I know that I have to call another <code>Public Shared Sub</code> so I need to do something here to retrieve from the <code>goToRequestedPage()</code> method. Below is the <code>goToRequestedPage()</code> method I would like the 'Public Shared Sub' to call (or at least perform the statements within it). </p>
  
  <p><code>AutoSaveCheckBox</code>, <code>Label1</code>, and <code>Response</code>, all state the following error:"Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class." </p>
  
  <p>As you can see, I would like a message box to pop up, asking the user to save, on top of allowing the user to go to the next page. The user is able to go to the next page, but how can I implement the <code>goToRequestPage()</code> method, or at least get my <code>msgbox</code> process to compile?</p>
  
  <pre><code>//Here is the Javascript 'on click' function for my next button:
  
  $("#Next").click(function () {
                  //PageMethods.NextPage(gbpageno)
                  $.ajax({
                      type: "POST",
                      url: "WebForm1.aspx/NextPage",
                      async: true,
                      data: "{'page':'" + gbPageNo + "'}",
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      success: function () { },
                      error: function () { }
                  });
  
                  if (splitType == "v") {
                      RenderBR('#CenterLeft', gbPageNo + 1);
                  }
                  else {
                      RenderBR('#CenterTop', gbPageNo + 1);
                  }
              });
  
  //Here is the Public Shared Sub NextPage() method:
  
  &lt;System.Web.Services.WebMethod()&gt; Public Shared Sub NextPage(ByVal page As Integer, ByVal textboxData As String)
          goToRequestedPage()
  End Sub
  </code></pre>
  
  <p>//Here is the goToRequestedPage() method I would like to call from Public Shared Sub       //NextPage(), or at least retrieve all functionality within it (Originally, this was //Protected Sub goToRequestedPage()):</p>
  
  <pre><code>Public Shared Sub goToRequestedPage()
          ' Declare Variables:
          ' Declare TransTableAdapter
          Dim TransAdapter As New EOL_DataSetTableAdapters.TransTableAdapter
          ' Declare previous page save confirmation
          Dim previousPageSaveConfirmation As MsgBoxResult
          ' Declare next page save confirmation
          Dim nextPageSaveConfirmation As MsgBoxResult
          ' Declare autosave checkbox status as Boolean value
          Dim autoSaveCheckBoxStatus As Boolean
          ' Declare page link as String 
          Dim pgLink As String
  
          ' If autosave checkbox is CHECKED...
          If AutoSaveCheckBox.Checked = True Then
              ' Save (Either Insert or Update) Transcription and go to next page
              TransAdapter.Insert(DataID:="NOT ASSIGNED", ID:=1, Book:="Book1", Page:="Page1", User:="User1", urlPDF:="url1", Transcription:="Transcription1", Transcription_Text:=TranscriptionTextbox.Text, isMaster:=0, isLocked:=0, Timestamp:="2004-11-15 11:37:10", CreateDate:="2004-11-15 11:37:10")
              ' Add the incremented page link back to the String
              pgLink = "http://br.mdsa.net/BookReader/index.html?id=ce425&amp;item=1&amp;format=Bitonal#page/" &amp; gbCurrentPage &amp; "/mode/1up"
              ' Declare Label 1 as The BookViewer on the Requested Page Number
              Label1.Text = "&lt;object id=""BookViewer"" data=""" &amp; pgLink &amp; """ height=""500"" width=""1500""&gt;&lt;embed src=""" &amp; pgLink &amp; """ width=""95%"" height=""100%""/&gt;Error: Embedded data could not be displayed.&lt;/object&gt;"
              ' Redirect to the Global Current Page Number
              Response.Redirect("~/WebForm1.aspx?page=" &amp; gbCurrentPage)
  
              ' If the autosave checkbox is UNCHECKED....
          Else
              If AutoSaveCheckBox.Checked = False Then
                  'Display Yes/No Save Confirmation
                  MsgBox("Would you like to save before continuing to the next page?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
  
                  ' For Previous Case:
                  If previousPageSaveConfirmation = MsgBoxResult.Yes Then
                      ' Decrement Global Current Page Number by one page if greater than page 1:
                      'If gbCurrentPage &gt; 1 Then gbCurrentPage -= 1
                      ' Save (Either Insert or Update) Transcription
                      TransAdapter.Insert(DataID:="NOT ASSIGNED", ID:=1, Book:="Book1", Page:="Page1", User:="User1", urlPDF:="url1", Transcription:="Transcription1", Transcription_Text:=TranscriptionTextbox.Text, isMaster:=0, isLocked:=0, Timestamp:="2004-11-15 11:37:10", CreateDate:="2004-11-15 11:37:10")
                      ' Add the decremented page link back to the String
                      pgLink = "http://br.mdsa.net/BookReader/index.html?id=ce425&amp;item=1&amp;format=Bitonal#page/" &amp; gbCurrentPage &amp; "/mode/1up"
                      ' Declare Label 1
                      Label1.Text = "&lt;object id=""BookViewer"" data=""" &amp; pgLink &amp; """ height=""500"" width=""1500""&gt;&lt;embed src=""" &amp; pgLink &amp; """ width=""95%"" height=""100%""/&gt;Error: Embedded data could not be displayed.&lt;/object&gt;"
                      ' Redirect to the Global Current Page Number
                      Response.Redirect("~/WebForm1.aspx?page=" &amp; gbCurrentPage)
                  ElseIf previousPageSaveConfirmation = MsgBoxResult.No Then
                      ' Decrement Global Current Page Number by one page if greater than page 1:
                      'If gbCurrentPage &gt; 1 Then gbCurrentPage -= 1
                      ' Go to Previous Page:
                      ' Add the decremented page link back to the String
                      pgLink = "http://br.mdsa.net/BookReader/index.html?id=ce425&amp;item=1&amp;format=Bitonal#page/" &amp; gbCurrentPage &amp; "/mode/1up"
                      ' Add the incremented page link back to the String
                      pgLink = "http://br.mdsa.net/BookReader/index.html?id=ce425&amp;item=1&amp;format=Bitonal#page/" &amp; gbCurrentPage &amp; "/mode/1up"
                      ' Declare Label 1
                      Label1.Text = "&lt;object id=""BookViewer"" data=""" &amp; pgLink &amp; """ height=""500"" width=""1500""&gt;&lt;embed src=""" &amp; pgLink &amp; """ width=""95%"" height=""100%""/&gt;Error: Embedded data could not be displayed.&lt;/object&gt;"
                      ' Redirect to the Global Current Page Number
                      Response.Redirect("~/WebForm1.aspx?page=" &amp; gbCurrentPage)
                  End If
  
                  ' For Next Case:
                  If nextPageSaveConfirmation = MsgBoxResult.Yes Then
                      ' Increment global current page number by one page
                      'gbCurrentPage += 1
                      ' Save (Either Insert or Update) Transcription and go to next page
                      TransAdapter.Insert(DataID:="NOT ASSIGNED", ID:=1, Book:="Book1", Page:="Page1", User:="User1", urlPDF:="url1", Transcription:="Transcription1", Transcription_Text:=TranscriptionTextbox.Text, isMaster:=0, isLocked:=0, Timestamp:="2004-11-15 11:37:10", CreateDate:="2004-11-15 11:37:10")
                      ' Add the incremented page link back to the String
                      pgLink = "http://br.mdsa.net/BookReader/index.html?id=ce425&amp;item=1&amp;format=Bitonal#page/" &amp; gbCurrentPage &amp; "/mode/1up"
                      ' Declare Label 1
                      Label1.Text = "&lt;object id=""BookViewer"" data=""" &amp; pgLink &amp; """ height=""500"" width=""1500""&gt;&lt;embed src=""" &amp; pgLink &amp; """ width=""95%"" height=""100%""/&gt;Error: Embedded data could not be displayed.&lt;/object&gt;"
                      ' Redirect to the Global Current Page Number
                      Response.Redirect("~/WebForm1.aspx?page=" &amp; gbCurrentPage)
                  ElseIf nextPageSaveConfirmation = MsgBoxResult.No Then
                      ' Increment global current page number by one page
                      'gbCurrentPage += 1
                      ' Go to next page:
                      ' Add the incremented page link back to the String
                      pgLink = "http://br.mdsa.net/BookReader/index.html?id=ce425&amp;item=1&amp;format=Bitonal#page/" &amp; gbCurrentPage &amp; "/mode/1up"
                      ' Declare Label 1
                      Label1.Text = "&lt;object id=""BookViewer"" data=""" &amp; pgLink &amp; """ height=""500"" width=""1500""&gt;&lt;embed src=""" &amp; pgLink &amp; """ width=""95%"" height=""100%""/&gt;Error: Embedded data could not be displayed.&lt;/object&gt;"
                      ' Redirect to the Global Current Page Number
                      Response.Redirect("~/WebForm1.aspx?page=" &amp; gbCurrentPage)
                  End If
              End If
          End If
      End Sub
  </code></pre>