Showing posts with label document. Show all posts
Showing posts with label document. Show all posts

Saturday, March 24, 2012

Wrapper for getElementsByTagName?

Does the client reference have a wrapper for document.getElementsByTagName like it does with ById/$get ?

Sorry the current version as well as the future does not not have any shortcut. But the future has a new shortcut which works on the css selector.


Is there some way through the client stack to check if a dom element has had a certain handler already added? Say I want to check if a textbox already has a handler {focus:SomeFunction} before I add the handler?


No, client reference doesn't have a wrapper for document.getElementsByTagName like it does with ById/$get


There's no 'wrapper' for ~ByTagName but you could easily write your own and put it in a utils file that you pull down. e.g.:

function $getTags(tagName){
return document.getElementsByTagName(tagName);
}

you can get a list of event handlers by calling get_events() on your element. To do what you're asking, you could say something like, var focusHandler = el.get_events().getHandler('focus'); if focusHandler is null, then you know you don't have anything handling focus yet.

Wednesday, March 21, 2012

XML creation

I need to create an XML document that i can use in a "Cascading DropDownList". I need to make it for Care Make, Model, and Year. I'm not sure exactly how to set this up or anyone has already done this so i don't have to recreate the wheel but I would appreciate any help at all.

Thanks,
QWERTYtech

Here is part of the solution.

http://ajax.asp.net/ajaxtoolkit/Walkthrough/CCDWithDB.aspx

And here is the part with the XML file.

http://www.devx.com/getHelpOn/10MinuteSolution/20382

You can have the web service return the result of the XPath query depending on the one you want.


What would i do if a car was produced from say 1991 to 2005?

would i have to make an entry for each year?


Hi,

I think you need to. Personally, I'd suggest using database for such scenario.

XML Parsing

I am fetching data from my server through AJAX, and some of the contained data is XML formatted. I am happy to instansiate XML Document objects if required, but it seems that at least some XML handling is included within the Framework. Is there any way to access the inbuilt XML processing client-side, or will I have to declare relevant objects or libraries and process them as I would in a standard HTML page?

Thanks in advance,

James

If you create a .NET class that represents the XML instead of passing back xml,( you pass back the object), you can return that class type in your web service method and the runtime will generate a javascript version of it off your [scriptmethod] for you.

so if I made a class in C# like

public class TesterClass {private int myVar;public int MyProperty {get {return myVar; }set { myVar =value; } }private int myVar2;public int MyProperty2 {get {return myVar2; }set { myVar2 =value; } } }

then if you hit your webservice.asmx/js you can see that it creates a javascript class version of it for you.

function MyTest(){MyProperty:0;MyProperty2:0;}

Now you can work with objects instead of XML.. slick eh?


I assume you're using Sys.Net.WebRequest to request the XML formatted data. In your call back function, you can retrieve the XML data by using the xml property of the WebRequestExecutor class. This only works, however, if the data's content type if text/xml. If it's a mix of plain text and XML, you'll have extract the XML data and load it into an XML DOM.


Just a sample call back function:

function request_callBack(executor, eventArgs){if (executor.get_responseAvailable()) { var xmlDom = executor.get_xml(); alert(xmlDom.documentElement.nodeName); }}


Thanks for the answers, but I've already got structured objects being passed back from a webservice. One of the fields that is passed back within the object contains XML. I can happily plug-in a cross-browser javascript XML library, but this is a bit superfluous if the XML handling is already being provided with my structured objects and their scripts. If anyone is able to confirm or deny the requirement to pass this XML field to the same objects that I'd use for HTML handling within an html file I'd be really grateful.

Thanks,

James


If you can convert your xml in that field into a JSON string, then you could use the method listed in the link below:

http://ajax.asp.net/docs/ClientReference/Sys.Serialization/JavascriptSerializerClass/JavascriptSerializerDeserializeMeth.aspx

XML to JSON Conversion Utility

Is there an XML Document to JSON conversion utility, like with Ajax.NET Pro, available with MS ajax.net?

TIA

See sample therehttp://www.phdcc.com/xml2json.htm