Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 89475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:43:21+00:00 2026-05-10T22:43:21+00:00

In this tutorial I am reading , Dave Ward creates a page that shows

  • 0

In this tutorial I am reading, Dave Ward creates a page that shows the server date in a label without using the update panel.

I am trying to learn how to create servercontrols that use ajax for partial postbacks where methods within the control are called from clientscript generated by the same control, and I think that learning how to convert this page to a server control would be a help me understand what servercontrols use instead of webmethods to expose their methods to clientscript.

I created the page, codebehind, and javascript exactly as the article indicated and got the sample to work.

So, to start trying to convert this to a servercontrol, I moved Dave’s Javascript for the page into a file, ~tests/JScript.js:

 function UpdateTime() {    PageMethods.GetCurrentDate(OnSucceeded, OnFailed);   }    function OnSucceeded(result, userContext, methodName) {    $get('Literal1').innerHTML = result;   }    function OnFailed(error, userContext, methodName) {    $get('Literal1').innerHTML = "An error occured.";  } 

And put the following class in my App_Code:

namespace foo {     /// <summary>     /// Summary description for ServerControlTest     /// </summary>     public class ServerControlTest : CompositeControl, IScriptControl     {         ScriptManager sm;         protected override void OnPreRender(EventArgs e)         {             if (!this.DesignMode)             {                 // Test for ScriptManager and register if it exists                 sm = ScriptManager.GetCurrent(Page);                  if (sm == null)                     throw new HttpException("A ScriptManager control must exist on the current page.");                  sm.RegisterScriptControl(this);                 sm.EnablePageMethods = true;             }              base.OnPreRender(e);         }          protected override void OnLoad(EventArgs e)         {             Literal lit = new Literal();             lit.Text = "<span ID=\"Literal1\" runat=\"server\">test</span><input id=\"Button1\" type=\"button\" value=\"button\"  onclick=\"UpdateTime();\" />";              this.Controls.Add(lit);         }         protected override void Render(HtmlTextWriter writer)         {             if (!this.DesignMode)                 sm.RegisterScriptDescriptors(this);              base.Render(writer);         }          [WebMethod]         public static string GetCurrentDate()         {             return DateTime.Now.ToString();         }          #region IScriptControl Members          IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()         {             return null;         }          IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()         {             ScriptReference reference = new ScriptReference();             reference.Path = ResolveClientUrl("~/tests/JScript.js");              return new ScriptReference[] { reference };         }          #endregion     } } 

Now, in my sample page, when I click the button, I get this error: PageMethods is not defined [Break on this error] PageMethods.GetCurrentDate(OnSucceeded, OnFailed);

How do I call GetCurrentDate from the clientscript that my control registers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:43:21+00:00Added an answer on May 10, 2026 at 10:43 pm

    There is actually no fully encapsulated method for implementing AJAX callbacks against methods of a server control yet, as of v3.5. It’s a very frustrating limitation.

    The most common solution is to create an HttpHandler in your server control’s assembly, then require that the handler be registered in the web.config. Look at how ASP.NET AJAX’s ScriptResource.axd is wired up in the web.config in ASP.NET AJAX 1.0, for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer That's something you could very well solve with WF (Workflow… May 11, 2026 at 9:39 am
  • added an answer This way (VB.NET code): For Each dkn As String in… May 11, 2026 at 9:39 am
  • added an answer Sorry... WPF's implementation of the EventTrigger only allows one routed… May 11, 2026 at 9:39 am

Related Questions

In this tutorial I am reading , Dave Ward creates a page that shows
I've been following this tutorial (lesson 6) in order to build and deploy a
I stumbled over this passage in the Django tutorial : Django models have a
In this question the answer was to flip on a switch that is picked
In this question someone asked for ways to display disk usage in Linux. I'd
In this situation I am trying to perform a data import from an XML
In this code I am debugging, I have this code snipit: ddlExpYear.SelectedItem.Value.Substring(2).PadLeft(2, '0'); What
In this particular situation, there are 9 automated steps in a process that take
In this particular case I'm trying to discover if a mylib.a file is 32
In this thread, we look at examples of good uses of goto in C

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.