Comment On Take a Walk on the Client Side

"Performance matters," Bob was told on his first day. The company prided itself on using the latest, cutting-edge techniques, and emphasized the use of client-side code to keep the application responsive. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Take a Walk on the Client Side

2012-07-23 14:17 • by Elezar (unregistered)
385539 in reply to 385448
Maybe I'm missing something or just rusty on javascript, but it looks like what this does when passed a search string is load the (blank) search page and populates the search bar with the provided string. Then only when the user presses enter or clicks the search image button, it executes the actual search.

The Page_Load() doesn't directly trigger the SearchImageButton_Click() as others seem to claim. It requires a manual action. The javascript just makes the search the default action when enter is pressed.

There could be reasons to require manual review of the search string before executing the search; without knowing the requirements it's hard to say if this is a WTF or not.


i dunno at what point the server-side Page_Load() is invoked, but the js sent back seems to be binding a form submit action to the enter key.

my guess would be that there's a funky ajax autosuggest handler already bound to (other) keypresses in the client-side search box, but Enter isn't set to submit [that] form initially [or rather, when when the search box is empty]

without more context in the OP it's rather dumb to call this a WTF

I'm reading this late, so maybe the text has been changed since you 2 commented, but there's nothing in the js that has anything to do with binding the Enter key (or any other key press for that matter). Here's the js that would be output:
<script language="Javascript">

var searchImageButton = GetControl("SearchImageButton", "INPUT");;
It's definitely triggering the click event on the button, and since that's being registered as a startup script, it will run as soon as the page loads...

Re: Take a Walk on the Client Side

2012-07-23 14:23 • by Elezar (unregistered)
385540 in reply to 385299
There seems to be something missing. We can't assume its a bad code by seeing the server code tells the client to post to the server.

The server code could be looking for other stuff collected by the client, and since the form data is missing, it wouldn't have it.

We don't know what the search method does/collects. If it requires a query field.

Also, what about search engines. If a get request hits the server this may cause a problem. This method would prevent a browser that doesn't execute javascript from issuing a post.

I agree. There could be other javascript that is doing a ton of processing based on the value in the SearchTextBox. As others have said, since the querystring variable name is Input, it's probably to handle old bookmarks. It populates that value to the SearchTextBox and reloads the page, so any client-side code can work using that value, populate some other input fields, and then it automatically resubmits it, with the submission now including all the data needed for the server-side processing.

Yes, everything done on the client-side could most likely be done server-side also, and then directly call the Search() method. However, you would then have the same logic in 2 places: Client-side for people going directly to the page, to reduce the amount of processing required server-side, and then server-side for the people with old bookmarks. If that logic is sufficiently complex, then it could make sense to do it this way, rather than duplicating the logic, and having to maintain it in 2 different places.

Re: Take a Walk on the Client Side

2012-07-30 08:35 • by md (unregistered)
385862 in reply to 385540
If "SearchImageButton" were wrapped inside an UpdatePanel the click event would trigger an ajax partial postback rather than a full postback, allowing the search results to be populated after the initial load without reloading the whole page. In which case, as others have said, the page would be perceived as loading faster.

Re: Take a Walk on the Client Side

2013-06-20 10:13 • by anonymous (unregistered)
Uhhhh, the WTF is on the very first line:
  protected void Page_Load(object sender, EventArgs e)
...that's ASP.NET, not Javascript; they're using server-side scripting to dynamically insert their client-side scripts, for no apparent reason.
« PrevPage 1 | Page 2Next »

Add Comment