Category Archives: Knockout

[RESOLVED] How to populate datatable in separate thread

suppose i have gridview in main thread and i want to populate datatable in another thread and populate my grid in main thread. is it possible....if yes then plzzz help me with source code.

hi

very nice question...i want to know too...

any idea?

If you want to load the data in another thread, to improve the responsiveness of the application, then you've really only two options:

1. Call the database reads in background in the code-behind. However, since you have to wait for the data before you can fill the grid you're not gaining anything; in fact you're probably harming the server resources.

2. Load the page, then asynchronously load the data. This gives the impression of a more responsive UI; the user still has to wait for the data, but they see something happening.

If you want the second approach then you have to do no data loading in the page (in chode behind), but load the page and in script, when the page has loaded in the client, create a call back to the server to get the data. You then have to extract the data and format it for display (since it's just raw data). The alternative is that you call a method that loads the data into the gridview and gets the gridview to render its HTML, then sends that back to the client. All-in-all you're giving yourself much more work that way.

Loading data asynchronously from the client can be very effective, but you have to do more script work and format the data. This can be achieve fairly easily with jQuery (http://jquery.com/) and things like Knockout (http://blog.stevensanderson.com/2010/07/05/introducing-knockout-a-ui-library-for-javascript/).

can u plzz come with example code of two way. thanks

[RESOLVED] Is creating page contents dynamically using javascript faster than loading different pages

I'm designing a website with different pages and every page has it's contents as like as `textbox, label, button, gridview` and etc.
after that I want to load every pages using `$("#xx").load(page url Address)` in jquery to prevent postback when the page is necessary.

is this method faster or following method:

I have just one page for example: `default.aspx` and a `javascript` file.
The page contents will be created using javascript dynamically just in one page  with `createElement` instead of loading different pages.

In the first method all `aspx` elements should be converted to `html` and then html elements must be transferred to the client but in the second method we won't have any `html` element transferring except for the `default.aspx` page and the elements will create in run-time using javascript.

"Faster" is not an easy term to define in this case as you're really not comparing similar things. It depends upon many factors, such as how many controls (both in aspx and html), what the data is, where it comes from, and so on.

There is definitely a trend towards more responsive, script driven sites using html and templating (eg jQuery, backbone, knockout, etc). The advantage of these is that only data travels across the wire, but the backend still has to process that data (eg send/update from database), so your backend still needs that logic. ASP.NET MVC makes building that architecture easier, but still doesn't sully support single-page applications, so you'd have to build all the logic yourself.

[RESOLVED] New project. Need advice.

<div>

Hello,

This is a 2-part question about dynamic rendering of ASP.Net pages.

In the first part, I want to render a page, but the controls that will define the page will need to be read from a source, e.g., XML, data tables, etc. I know how to use XML and XSLT, so this might be a good option. However, don't jump onto any conclusions before you read part 2.

For part 2, I need a system where the user will define what information will be used to build the page I mentioned above. Sorry if that's was a bit unclear. Here is an example: Let's say I want to sell PC monitors and TV's on my website. My boss will come in, define that the product will be a monitor, can be a brand of Samsung, Sony or Lenovo, size 17", 19" or 21" and then respective prices. Then he will enter another product, this time a TV, with different set of specs: Plasma or LCD, size 42", 46" or 50", comes with a Wi-Fi connection or not, yada yada yada. 

As you can see, the two products are not 100% the same and I don't know anything about them before I render my page. I cannot assume they will have a limited set of specs so creating static content is out of question. With this type of design, if my company wants to sell cell phones in the future, all I need to do is let the boss enter the information about the product and my sales page will render it correctly.

I would like to hear your ideas about how I can design this system so my sales page will read and create the controls, e.g., combobox control for size, checkbox for Wi-Fi connectivity, etc. on the go. I appreciate your help!

</div>

I've had to do something similar, in my case each object had a user defined "schema" which could be modified dynamically and then populated from an EAV datasource.  As I had dynamicall generated objects to work with I went with MVC (after modifying the Object.cshtml file to allow "Deep Dive" models).  Mainly this was to force the UI blocks which were used to be independent.

In the webforms worlds, you can do the same thing by dynamically adding usercontrols in the control tree.

I would strongly resist XSLT for presentational purposes as in my experience it becomes a maintenance nightmare (especially with localisation, validation, etc) and only really works for simple static pages which could be delivered much more simply as flat html.

Thank you martincjarvis!

Can the mods please carry this topic to MVC? I guess this belongs there.

Thanks!

Yes, avoid XSLT for those reasons. Use XML by all means, but I'd use LINQ-XML to read the XML and construct custom objects.

Essentially you've two unique things to render: the product (name, description, picture), and specs (again, name, description, picture, etc). I did a similar site years ago, where for the line items (specs) we had a finite set of types, so we just had a data structure like this:

internal class Item
{
  int ID;
  string Name;
  string Description;
  string imageUrl;
  LineItemType ItemType;
  object Value;
}

and

  internal enum LineItemType {ComboBox, ListBox, CheckBox, TextBox };

That sort of thing. Then in the code that constructed the item we had a simple switch statement to check the ItemType and construct the right control type.

We are also using XSLT approch in our projects and and do below :

1) Our stored Procedures returns XML.

2) We uses XSL files as a view where XML can be directly applied to return HTML.

3) We are using XSLTToJSON for JSON Serialization , I would like you to check the performace of this  that It is 200% faster then JSON.net with compiled XSL.

4) With .Net 4.0 supports compiled XSL. The XSL transformation is amazingly fast and  It is powerful enough.

 

I would say write modullar javascript for different modules for your projects, converts XML into JSON and then you can use KnockOut.js + jQuery templating to create amazingly dynamic, high performance and flexible.

 

Please let me know, if you need any help on this

Thanks

Sunil

 

 

Thanks

[RESOLVED] Creating a list on the page

I can add a user control dynamically but what is the best way to be able to create a list of objects on the page for retrieval later, let's say I'm adding 3 items of something by selecting from a dropdown and clicking on a button.  Each time I try the past objects are lost and only the new item is added?

are you using IspostBack on page_load event?

it might be that u r clearing list on page_load without checking IsPostBack

posting codebehind code would help...

I don't have the code to post at hand, I was merely asking others for their best method for doing this kind of thing.  What would you recommend?

Hi,

Because the asp.net do't keep the created dynamicly control staate.

So you should create them every time when the page post to server.

Another way is that you store them into cache or session.

But it also has the drawbacks, it will lay more memory stress over the asp.net server.

In the end I have used knockout.js to create them client-side and used ajax to store them.

[RESOLVED] How best to create a treeview

I currently am using ajax on my page to get data.  In this case it's a list of groups which may fall under a root group or another group.  I need to create a treeview whereby I can list all these groups and there is no limit to how far a group may be nested.  Therefore I want to ajax load sub items whenever a node is clicked because I don't want to cause a postback.

What is the best way to do this?  I have looked at other jQuery type treeviews which aren't helping and I was wondering whether putting an asp TreeView in an updatepanel might be better?  I am using Knockout so if it's something thats possible to do and put in a template then even better.

Hi,

I think the best way would be using jQuery. asp TreeView sometimes is not compatible with updatePanel.

See http://msdn.microsoft.com/en-us/library/bb386454.aspx

The following ASP.NET controls are not compatible with partial-page updates, and are therefore not designed to work inside an UpdatePanel control:

  • TreeView control under several conditions. One is when callbacks are enabled that are not part of an asynchronous postback. Another is when you set styles directly as control properties instead of implicitly styling the control by using a reference to CSS styles. Another is when the EnableClientScript property is false (the default is true). Another is if you change the value of theEnableClientScript property between asynchronous postbacks. For more information, see TreeView Web Server Control Overview.