Recently I built a little asp.net shout box for a friend of mine, which was very easily done, but I was thinking how cool the shout box would be without post back! It would be pretty much like a chat room. Basically the labs showed me everything I needed to know as far as using the textbox, button and listview to make this work, but how do I update the listviews datasource? Basically I would need to use the textbox for the message and somehow bind the membership username in front of it. Update the datasource which most likely would be an xml file and refresh the web service. It all sounds so easy and I know it would take me about 20 minutes in Asp.net 2.0, but like I said I just can't tie it all together using Atlas. Any ideas would be greatly appreciated!
(Note: Bertrand has ablog post which should be pretty close to what you are doing.)
This should indeed be pretty trivial. Lets assume you already have a page with a datasource, a listview, a textbox (for the message) and a button, and you have set up the right bindings. (If this is a problem, let me know, and I will show you how to set this up properly.)
All you should really have to do is invoke a method on the datasource when someone clicks on the (save) button. Atlas has a concept called "actions", which are kind of like eventhandlers. This basically allows you to specify what actions should be performed when an event is raised. In your case, the action you want to perform is "update the datasource". You can do this with the following code:
<button targetElement="myButton">
<click>
<invokeMethod target="myDataSource" method="update" />
</click>
</button>
That is basically it. The datasource should take care of submitting the bound values (ie. your textbox value is the message) to the webservice's update method.
As a side note: if you want to quickly find out what kind of (public) methods/properties/events a control supports, you could take a look at its getDescriptor function. Ralph Sommerer hasposted a more readable version of the atlas sources, which should simplify this.
HTH.
Update: I should clarify this a little bit. You actually have to call a function "addItem" on the listview first. The listview should then add an item to the datasource (with no values), and show a new item bound against this new datarow. A user can enter values for this new item, and save it by clicking on the button the way I defined it in this post. One way to achieve this, is by adding another button:
<button targetElement="addMessage">
<click>
<invokeMethod target="myListView" method="addItem" />
</click>
</button>
Additionally, you could also tweak this a bit and for example disable this button after you added an item, to prevent a user from adding multiple items and save them at once. To do that, add a setProperty action which enables/disables the button when you add an item and save an item, respectively.
Thank you! I did find Bertrand's blog post yesterday and got pretty far.
I do have a question though
![Smile [:)]](http://pics.10026.com/?src=/emoticons/emotion-1.gif)
I love the idea of disabling the add button, but could I take it a step further and only show the controls if a user is logged on? It looks like the first PDC demo would show me how to do this, but unfortunately I can't get it to work, because I seem to be missing the Atlas:panel control which is what is hiding things based on the actions. I am guessing we will have this control in a matter of days or weeks hopefully, but is there any other way without postback?
No comments:
Post a Comment