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 8930309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:51:50+00:00 2026-06-15T08:51:50+00:00

Frequently GAS users ( me too ) do not use the ServerHandler.addCallbackElement method or

  • 0

Frequently GAS users (me too) do not use the ServerHandler.addCallbackElement method or use in a way which does not cover all controls.

What is a background to have this method at all? Why GAS developers introduced it? Is it simpler to pass all input widgets values to all server handlers as parameters?

The documentation does not provide answers to these questions.

I see the following causes

  1. Adding widgets as callback elements reduces traffic between browsers and GAS servers in case of several handlers which handle different sets of controls. Here is a question. How much traffic it saves? I think maximum a few kilobytes, usually hundreds of bytes. Is it worth, considering the modern internet connections speed, even mobile connections.
  2. A form contains a table-like edit controls with multiple buttons and it is comfortable to handle row elements with the same name. This issue is easily avoided by using tags. See the following example. If the tags are used for other purposes it is not a problem to parse the source button id and extract the row number.
  3. Limits of technology used behind the scenes. If there are such limits, then what are they?
function doGet(e) {
  var app = UiApp.createApplication();
  var vPanel = app.createVerticalPanel();
  var handler = app.createServerHandler("onBtnClick");
  var lstWidgets = [];
  for (var i = 0; i < 10; i++) {
    var hPanel = app.createHorizontalPanel().setTag('id_' + i);
    var text = app.createTextBox().setName("text_" + i);
    text.setText(new Date().valueOf());
    var btn = app.createButton("click me").addClickHandler(handler);
    btn.setTag(i).setId('id_btn' + i);
    var lbl = app.createLabel().setId("lbl_" + i);
    hPanel.add(text);
    hPanel.add(btn);
    hPanel.add(lbl);
    lstWidgets.push(text);
    lstWidgets.push(btn);
    vPanel.add(hPanel);
  }
  // The addCallbackElement calls simulate situation when all widgets values are passed to a single server handler.
  for (var j = 0; j < lstWidgets.length; j++) {
    handler.addCallbackElement(lstWidgets[j]); 
  }
  app.add(vPanel);
  return app;
}

function onBtnClick(e) {
  var app = UiApp.getActiveApplication();
  var i = e.parameter[e.parameter.source + '_tag'];
  var lbl = app.getElementById("lbl_" + i);
  lbl.setText("Source ButtonID: " + e.parameter.source + ', Text: ' + e.parameter["text_" + i]);
  return app;
}
  • 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. Editorial Team
    Editorial Team
    2026-06-15T08:51:51+00:00Added an answer on June 15, 2026 at 8:51 am

    Great Question.

    “How much traffic it saves?” I don’t think we know yet, but I expect it will get more efficient over time. Here is another discussion on performance. Only extensive testing and improvements from Google will really allow us to identify best practices, for now all I can say is that ClientHandlers are clearly going to be better than ServerHandlers whenever possible.

    As JavaScript developers I think we are predominantly use to doing stuff client-side, then we think of PHP/ASP as server-side tools. My understanding so far is that our GAS code is actually running both client and server side (at the very least it’s calling server side functionality) but it sure seems like there’s more going on server-side than we realize, and on the client-side this seems to result in somewhat “compiled” code. I kinda recognize some of this multi-tier deployment from my Java experience.

    Since there are a lot of ways of doing the same thing, Google can take advantage of the fact that our code is not directly interpreted (by either side) to do things that would not necessarily make sense if we were writing the code by hand. This is why I think it will become more efficient than other solutions, eventually but probably not yet. For now I’d suggest steering clear of GAS if you are worried about performance. Maybe just for fun try looking at the source of your client-side Web-Apps at runtime (view source). So in order for them to do things most efficiently, I imagine they will benefit by having us define things in a very high-level way. This gives them the most flexibility in how they interpret our code.

    To specifically address your second question I personally think of the Handler Function onBtnClick() as running on the Server-Side, whereas the Tags you refer to (and most of the doGet) would be in the browser’s engine on the client-side. I can see how the functionality would be much more flexible (efficient and powerful) on the server-side if they have an idea ahead of time as to how much memory they would need to handle specific events/requests. (Clearly if each getElementById() call was running a separate request, that would be like clicking a link to a new mini-webpage each time.)

    So now the question is why can’t my handler just automatically create parameters with just the stuff I use in my handler function? The only reason we are asking this question in the first place is because there is some stuff in the UiApp which seems to be available on both ends. The UiApp is already in the scope of both the doGet and onClick but the variables defined in doGet are not, so these values need to be either

    • explicitly saved like ScriptProperties.setProperty() or
    • put into the UiApp somewhere with an Id or
    • explicitly given to the Handler function using addCallbackElement()

    Notice how you had to addCallbackElement(lstWidget), because it was not created with an app.create… constructor within the UiApp object. My guess is that GAS is implementing XML compliant SOAP calls to a web-service on the Google end, we may be able to figure this out by really studying the client-side source code. Just to reiterate we could also use setProperty() it does not really matter, or even save them via JDBC and then retrieve them with another connection from within your handler function but somehow the data needs to be passed from the Client to the Server and vice-versa.

    From a programming perspective there is a lot of stuff available in the scope of your client-side doGet function that you probably would never want to pass to the server, or there may be functions in the scope of the server-side doClick() with the same name as functions on the client-side but they may actually be calls to totally different library functions maybe even on totally different hardware (even though from the developer’s perspective they work the same way).

    Maybe the Google team has not yet really decided on how the UiApp really works yet, otherwise they would just force or at least allow us to put everything in there. Yet another observation when we call UiApp.getActiveApplication() based on it’s name it does not seem like a constructor, but rather a method that returns a private instance from the UiApp object. (Object being a class that was previously instantiated and supposedly initialized somewhere.) I may not have 100% answered your question but I sure did try, any further insight from the community would clearly be appreciated.

    Now I may be straying off-topic but I also imagine the actual product will continue to change as they do more to improve performance in the long-term, and if we still feel like we are writing client-side code as a developer then that is a success for Google. Now please correct me if I have stated anything wrong, I have just recently started using these tools and plan to follow up on this question with more specifics as I learn more but as of right now that is my best interpretation.

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

Sidebar

Related Questions

I frequently encounter a code smell when I use the Enumerable group_by method. Some
After frequently coming across recommendation not to use leading and double underscores in C/C++
I frequently use git stash and git stash pop to save and restore changes
I frequently deal with UTF-16LE files encoded on windows which have a \r\n carriage
I frequently code numerous experiments to test various algorithms, libraries, or hardware. All code,
I frequently use Resharper's 'Go to Declaration' (ctrl + b in the Resharper Default
I frequently write C# code that has to use magic strings to express property
I frequently use the two functions below to read the contents of a file
Frequently, I use functions to shape or numerically alter data that I'm passing to
I frequently use git stash and git stash pop to save and restore changes

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.