JQuery Core / Data or Custom Attributes (Data-Driven)
A similar question was asked here when storing information in a given html element.
I'm still green for jQuery, but I'm looking for a better way to store information on a page. I have a repeater that contains one image per item. These images are clickable and can fire this jQuery event. The problem I'm running into is objects where the relay needs to contain certain information (like "Subtext", "LargerImage", etc.) that I would like to get from the page.
Core / Data in jQuery does this just fine, but we still need to build a jQuery statement from C # since all the data is stored on the server. To clarify a bit, this is storing information on a page from a database, which is slightly different from arbitrary information available through jQuery.
I am not limiting this question to "binding a custom attribute to an element" because I got the idea of ββgenerating JS Struct from C # codebehind to store information, but I avoid any code by generating code scripts (or trying).
Custom attributes from HTML5 (ie "data subtext") are also a possibility, as I can easily add them from the itemdatabound event:
sampleImageElement.Attributes.Add("data-subtext", "And this what the image is about");
I'm a little confused about browser support for this particular attribute, or if it's even best practice, so early in the game. If custom attributes are the way to go, then it's easy to implement. If jQuery can do the same, I would like it to be stated that way, at least for my own understanding.
Any thoughts are appreciated.
source to share
I am answering this question for stackoverflow data storage purposes only, since this is the solution I have moved forward with for this scenario. The AJAX call is fully justified for any large datasets and is a direction I would definitely stay differently.
I went to the "data-" field in the HTML5 spec provided by the jQuery metadata plugin.
I wrote a short extension method in the Web.UI.AttributeCollection class called "AddMetaData" that takes an IList as well as the string "Key" to make it easier to nest into a given page element.
I am not flagging this as an answer yet, as there may be some community feedback in my own direction.
source to share
To figure out what's going on in ASP.NET, after the page has been submitted to the client, the objects that the relay is bound to on the server will be destroyed and then restored after each page back.
Sounds like you want some sort of tooltip effect when the content is fetched from the server via AJAX? There are many different hints.
which can be used for this. Then you can configure a web service or page method to retrieve the relevant data from your data source.
Of course, you could display the HTML content sent to the client while processing the request, and just hide that markup. Then write your own plugin to display the markup in the required form.
source to share