Showing posts with label client. Show all posts
Showing posts with label client. Show all posts

Monday, March 26, 2012

window.onload alternative

I believe there is a method in the Microsoft AJAX framework that is part of the client side (javascript). That allows multiple onload events to be registered easily.

I can't find it in the documentation though. Can someone point me in the right direction?

Thanks

You can use Sys.Application to register/deregister load and unload handlers.

Wireless troubleshooting

Hi,

I have a website (asp.net - ajax) hosted in a computer. I can access it through internet. Everything works fine except when the client computer has wireless mouse, when i access the website with that kind of machine the mouse cursor get very slow. I accessed thewww.asp.net web site and got the same problem. Seems to be an AJAX incompatibility.

Any suggestions?

Thanks

Fcvl

Ajax has nothing to do with hardware nor the mouse.. asp.net has been going through some upgrades live (I would presume) - no anything that is being slow is either the connection the pc in question has and is really slow or the device driver for the mouse (or maybe the mouse is low on battery juice) would be the issue...

Wish: ClientSide EventHandling By Reference

Hello to all!

I have discovered that event handling in the client side is done by copying the function into the event handler list array and not by referencing it. That is very bad I think. I wish for the next release of the MS Ajax Library an event handling by reference. Below is some code to make clear, what I am meaning.

1 Type.registerNamespace('Demo');23 Demo.Class1 = function () {4this.className ='this is class one';5 _evtHandler =new Sys.EventHandlerList();6 }7 Demo.Class1.prototype = {8 addDoSomethingEventHandler: function (handler) {9 _evtHandler.addHandler('onDoSomething', handler);10 },11 removeDoSomethingEventHandler: function (handler) {12 _evtHandler.removeHandler('onDoSomething', handler);13 },14 doSomething: function () {15 alert('I am doing something.');16 var f = _evtHandler.getHandler('onDoSomething');17if(f) {18 f();19 }20 },21 dispose: function() {22 alert('I am disposing now (' +this.className +')');23 }24 }25 Demo.Class1.registerClass('Demo.Class1',null, Sys.IDisposable);2627 Demo.Class2 = function (id) {28this.className ='this is class two.';29this._id = id30 }31 Demo.Class2.prototype = {32 methodOne: function () {33 alert('ID: ' +this._id +'\nMethod One knows that something is done.');34 },35 methodTwo: function () {36 alert('ID: ' +this._id +'\nMethod Two knows that something is done.');37 },38 methodThree: function () {39 alert('ID: ' +this._id +'\nMethod Three knows that something is done.');40 },41 dispose: function () {42 alert('I am disposing now (' +this.className +')');43 }44 }45 Demo.Class2.registerClass('Demo.Class2',null, Sys.IDisposable);4647 var obj1 =new Demo.Class1();48 var obj2 =new Demo.Class2('obj2');49 var obj3 =new Demo.Class2('obj3');5051 obj1.addDoSomethingEventHandler(obj2.methodOne);52 obj1.addDoSomethingEventHandler(obj2.methodTwo);53 obj1.addDoSomethingEventHandler(obj3.methodOne);54 obj1.doSomething();55 obj2.methodOne = function () {56 alert('Someone has overwritten me.');57 };58 obj1.removeDoSomethingEventHandler(obj2.methodOne);59 obj1.doSomething();60 obj2.methodOne();61 obj3.methodThree();

First observaion is that becauseobj2.methodOne() has been over written id couldn't removed from the event handler list. The second one is that the variablesthis._id are undefined when calling the functions by raising the event. Calling the methods directly from an instance does work, see line 61.

I need some workaround to save an instance, too, not only a copy of its methods in order their instance variables are not undefined. Any Ideas are welcome.

Yavuz

First of all your code seems to be buggy.

obj1.addDoSomethingEventHandler(obj2.methodOne);

When the methodOne is invoked the this pointer will not be obj2.

Here is the fix.

var fn = Function.createDelegate(obj2, obj2.methodOne);

obj1.addDoSomethingEventHandler(fn);

Now you can remove the handler using

obj1.removeDoSomethingEventHandler(fn);

This is unaffected whether or not you set obj2.methodOne to something else.


Hello Rama!

That was not a bug. It was a question how to solve this problemSmile Thank you for your answer.

Now the function is copied into the delegate. Ifobj2.methodOne() is changed, the changed method isn't invoked. But thats another story I think. It's a situation which occurs rarely i think where you have to change a method at run-time.

I could not find a documentation about theFunction.createDelegate() method. Have I to go through the debug.js-files?

Yavuz


Looks like it has been not documented yet. The doc writers missed it. There are two function Function.createCallback and Function.createDelegate, they are widely used in ASP.NET AJAX. You can look at the source as it is easy to understand utility.

I will do it. Thank you.

Saturday, March 24, 2012

without server side scripting, can we upload a file using client side scripting if destina

without server side scripting, can we upload a file using client side scripting if destination folder and config file settings are known? is it possible?

avdp211:

without server side scripting, can we upload a file using client side scripting if destination folder and config file settings are known? is it possible?

I don't think it is possible.

You use the the HTML input file control and when you post the request, on the web server you need to read the data and save it to a file, so there has to be some interaction with the server to handle the post request.


Not possible via JavaScript, by design.

http://geekswithblogs.net/rashid/archive/2007/08/01/Create-An-Ajax-Style-File-Upload.aspx


thanks

ok then shall it be possible with http put method?


It's fairly certain that we'll never see a client side method for automating file uploads. The security concerns are just too great.

If you use a custom ActiveX control you can do it (think Windows Update), but it's impossible in JavaScript.

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

writing json back to client

I am making an xmlhttp request (using the scripts provided inAjax for Web Application Developersby Kris Hadlock) to get data from an aspx page. When I create a dataset and return xml with an xmldocument it works fine. I am using the following where dsreturn is the getXML of the dataset.

Dim xdocAs XmlDocument =New XmlDocument()

xdoc.LoadXml(dsreturn)

xdoc.Save(Response.OutputStream)

The problem is that I also want to return json. I have created a biz class to parse a dataset and return a json string. I know this works because I have used it in other web services. When I do this I get nothing. I think that my problem is how to return the json string in the response.outputstream. I am not sure how to do this. Just using response.write doesnt seem to work.

Thanx

Have you considered using page methods instead of doing it all by hand? They return JSON by default.

WSE 3.0

When should we see WSE support? How can I secure my web services to be consumed on the client using a UsernameToken? I have a wse 3.0 web servive which uses a custom UsernameTokenManager which is hooked into a forms authentication database. Problem is, how am I suppose to consume these web services on the client using .net ajax 1.0? Anyone have any idea's on securing my web service so only authenticated users can consume them? The transport is not my concern as I'm using SSL.

hi,

http://msdn2.microsoft.com/en-us/library/aa480575.aspx

XML and Webserivces

Hi All,

I have created a webservice that returns XML data to be processed by the client.

The returned XML contains a complex type that I created, as well as having a number of nested objects on which I have used the XMLARRAY / XMLARRAYITEM.

Fragment of test XML shown below...

<?xmlversion="1.0"encoding="utf-8"?>

<Testxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns="http://tempuri.org">

<test1>201</test1>

<test2>Blah Blah</test2>

<test3>3</test3>

<test4>51</test4>

<TestTest>

<Inner>

<inner1>300</inner1>

<inner2>TEXT</inner2>

<inner3>TEXT</inner3>

<inner4>TEXT</inner4>

<inner5>TEXT</inner5>

<inner6>TEXT</inner6>

<inner7>TEXT</inner7>

<inner8>TEXT</inner8>

<inner9>TEXT</inner9>

<inner10>TEXT</inner10>

</Inner>

<Inner>

<inner1>301</inner1>

<inner2>TEXT</inner2>

<inner3>TEXT</inner3>

<inner4>TEXT</inner4>

<inner5>TEXT</inner5>

<inner6>TEXT</inner6>

<inner7>TEXT</inner7>

<inner8>TEXT</inner8>

<inner9>TEXT</inner9>

<inner10>TEXT</inner10>

</Inner> </TestTest>

</Test>

Now when I use the test harness the XML is generated exactly as I require.

Also I can reference the returned data on the client, for example by using arg.test1 would return '201'.

My probelms/question are these...

1> How do I access the inner array items. For example how would I access elements under TestTest?

2> How do I convert the returned data from the webservice into valid xml on the client? Every time I try and do this I get the error 'XML document must have a top level element'.

I cant understand why it says it is not valid as every other application I have has no problem with the XML that is generated,

Can anyone point me in the right direction as I cant see where the problem is.

Thanks in advance

Problem sortedSmile

Once I found out about the service using JSON by default it was very straightforward.

I looked at the JSON formatted data that was sent with the response. From there it was obvious how to call the array items.

For example arg.Level1[1].Level2Value

Didn't know much about JSON before this but it is a great format (compared to XML) to use when you want to handle stuff on the client in javascript. Even handles custom objects with ease.

Hope this helps somebody