0

This is a design question. I hope you guys will be able to help me with this.

I am developing an autocomplete control. Its basically a service based control, where the responsibility of the service call is to fetch HTML of the suggestion list (drop-down menu) when user enters a few words.

The server side code is in C# and the client side in JQuery/Javascript.

The control has been developed to use two modes:

  1. An ASP.NET control (which initializes a jQuery widget in the generated response).

  2. A standalone jQuery widget that uses a server side HTML generation engine.

I have kept the HTML generation engine of the suggestion menu (drop-down menu) on server. Control users can choose to cache their datasource on server. If caching is not enabled, the datasource is sent to server in each service request for HTML generation.

My question is - Should I write an HTML generation engine on client side (JQuery/Javascript) also ?

So far, I have found following pros and cons of "writing a separate client side HTML engine":

Pros:

  1. Faster HTML generation for small to average size of suggestion list as request to server is avoided.

  2. No server side dependency, the jQuery widget mode will be completely standalone as no server side code is required.

Cons:

  1. Code duplicacy : Same generation engine in both C# and jQuery/javascript.

  2. Increased maintenance : As new features/functionalities are added, changes will have to be done on both sides.

Apurv
  • 1
  • 1

1 Answers1

1

I would generate all required dynamic html on client side. This is a lot faster.

The server or web service could return a set of results(JSON). I would use that to populate and display the results view in javascript.

the asp.net control too would render data as JSON and use javascript on the client side to display it as required.

The cons you mention, of code duplication and increased maintenance should not arise if you consume your data in html, regardless of if it is being rendered by a control or obtained from a service.

nunespascal
  • 17,584
  • 2
  • 43
  • 46
  • @nunespascal: The ASP.NET control is not rendering full HTML, it is just creating a text box and applying the jquery widget to it. On key press, it would still use service. The main problem is suppose even if I implement ur approach, then also, while going fully client side, I will have to write a matching engine on both client and server(code duplicacy again), that would return matching items, won't I? – Apurv Feb 02 '13 at 08:38
  • What do you mean by a matching engine? Are you referring to the logic to serialize your data object on the server and to deserialize it on the client? – nunespascal Feb 02 '13 at 09:00
  • No. The code block/function that would return the filtered result depending on the letters entered by user – Apurv Feb 02 '13 at 11:48
  • The matching engine would reside only one your server. Clients responsibility is to send the currently entered letters and to present the search results. – nunespascal Feb 04 '13 at 04:00