Note that there are some explanatory texts on larger screens.

plurals
  1. POWebmethods in base page, works in one inherited page, not but in a second
    text
    copied!<p>I am trying to move my common <code>PageMethods</code> to a <code>MyBasePage</code> in which two <code>.aspx</code> pages will inherit. </p> <p>On <code>page1.aspx</code>, I can call the <code>PageMethods.SetFormID("abc")</code> fine.</p> <p>However, on <code>page2.aspx</code>, I get 'PageMethods is undefined' error, when trying to access the same method <code>PageMethods.SetFormID("def");</code></p> <p>Here is my pseudocode:</p> <ol> <li><p><code>MyBasePage</code> inherits from <code>System.Web.UI.Page</code>, and includes the <code>WebMethodAttribute</code>, the method is both static and public.</p> <pre><code> [System.Web.Services.WebMethod] public static void SetFormID(string formID) { //save formID as a session variable; } </code></pre></li> <li><p>Both pages inherit from <code>MyBasePage</code></p> <pre><code>public partial class Page1 : MyBasePage public partial class Page2 : MyBasePage </code></pre></li> <li><p>Both pages include a <code>ScriptManger</code> line with <code>EnablePageMethods="true"</code></p> <pre><code>&lt; asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnablePartialRendering="true"/&gt; </code></pre></li> <li><p>From the javascript on each page, I call </p> <pre><code>PageMethods.SetFormID(id); </code></pre></li> <li><p>I transition to <code>Page2.aspx</code>, by calling either: </p> <pre><code>window.open("Page2.aspx"); -or- window.location("Page2.aspx"); </code></pre></li> </ol> <p>Thus, I must have done something wrong with <code>Page2.aspx</code>, so I tried saving <code>Page1.aspx</code> as <code>Page2.aspx</code> (thus, both pages would have identical code, except the class name). Page 1 works as before, but Page 2 fails with <code>PageMethods is undefined</code>.</p> <p>I then tried to set Page2 as the startPage in VS, and have it call Page1. Page 2 can now call the PageMethods fine, but Page1 will fail.</p> <p>Anyone have any ideas on what is happening here? Should I be able to call <code>PageMethods</code> defined in my baseClass from any page derived from it? Maybe it has something to do with how the page is transitioned?</p> <p>PS: it is a VS2012, .NET4 project</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload