PDA

View Full Version : yui-ext and ASP.NET 2.0



LoneTiger
23 Jan 2007, 9:06 AM
Hi everyone,

I read some posts about yui-ext and ASP.NET 2.0 going hand in hand. But the main porpose of those posts was to bypass asp.net in order to use multiple forms and so on.

What I've been trying to do is reusing the entire ASP.NET server side functionality and implementing some aditional handling at client side. I'd appreciate if anyone who reads this through has some neat ideas or better implementations.

My first try was to have a complex layout and each of the content panels would have a diferent .aspx assigned. No trouble setting up the initial layout and updating the panels to initial pages.

The first thing I tried was implement a server side button that with no aditional code on server posts the form back through client side, javascript controled way, while preserving viewstat of the page, setting the IsPostBack property correctly and all that. I managed to accomplish that with appending and event handler to each of the content panels for click event and checking for the presence of __doPostBack in the handler. Afcourse the appropriate parent form had to be found before actusaly calling formUpdate on the panel's element.

That part worked perfectly fine. Full server postback occured on server side, all the viewstate control values were there, so as it should be. The problems started when I tried to do the same from DropDownList control which when AutoPostBack is set to true has a onChange property set to timeout and __doPostBack. Problem is, that the change event as it seems does not get bubbled up to the content panel but it gets suppresed by the SELECT element of the dom. I have overriden the __doPostBack with:

__doPostBack = function (target, argument)
{
alert('__doPostBack');
}

Well, second guess was to find the first child element with tagName form in the callback of the initial update call and then on each formUpdate and append a post event handler to the form itself. I have written some extensions to YUI.ext.Element to find the correct form. Now I'm dealing with finding which event to catch in order to do that. Stuck here.

Just wanted to share this with other people in case someone was going the same way or has some ideas. Doing this I encountered some bugs and questions:

- if you specify loadScripts = true on the UpdateManager of the content panel and then execute form update, javascript always produces error 'Syntax error'. This would be urgent to use to enable server side panel switching. Similar to what you can do in former ATLAS - AJAX.NET or whatever it's called now; UpdatePanel.Update().

- It would be very neat if there were some list of all native events - I mean their aliases in yui, sorted by html elements. So one could just look it up. Is there one?

- Are there other elements besides SELECT for whoom events are not cought by their parent elements?

- in the event handler of the addHandler call I noticed you get diferent objects as srcElement (1st argument) in IE and FireFox? Should this happen? In IE you can read the actual event source element with property srcElement and in FF .originalTarget. Is this OK? Or am I missing something?

If anyone is interested I can post the Element extensions I used for searching forms and rest.

Well, I hope I maby at least helped someone with this. Bottom line is its not that hard to sustain ASP.NET server side and take full advantage of yui-ext.

rodiniz
23 Jan 2007, 9:17 AM
My aproach is very simple... when I use the Layout I don't use postbacks I use Ajax and that
saves me a lot of headache.
If you read Jack initial post for BorderLayout you will see that he is talking about web 2.0 ...so
he was talking about using it without postbacks.

LoneTiger
23 Jan 2007, 9:25 AM
Hi rodiniz,

Sorry I forgot to mention we were developing a quite security touchy web administration, its business logic is hidden from the client completely, so using full postbacks is one of the fundamental reuqirements.

I'd much rather go past the asp.net still hanging on to ancient technologies and use only AjaxPro for server communication, but the requirement stands. Content must get rendered at server and returned as html while preserving asp.net server side functionality, already made server controls and other things.

If you don't do a correct postback of the correct form to the server, the viewstate and bound server control values are lost in time and space. That's why I was whondering weather someone already made some progress in this direction.

But thanks for pointing out what I should read. Will get right on it :)