ASP.NET and AJAX: So Freaking Easy (Part 2: Triggers)
My last post highlighted how easy it is to implement asynchronous postbacks using ASP.NET and AJAX but didn’t go into much depth. Here I’m going to explain a little bit more (at least so far as I’ve learned!) about triggers. You most likely have these on your site already and just don’t know it (or do). Any time someone presses a button or selects something from a dropdown that automatically posts back, that’s a trigger. Typically, this performs a full page post back, reloads your page, and performs the designated code for that trigger. In ASP.NET/AJAX, you can decide whether or not you want to trigger a full page refresh or a partial page refresh simply by designating a trigger.
Between your <asp:updatepanel> tags and outside your <contenttemplate> tags, create a <triggers> tag. Inside this tag, you have the option to create two types of tags: <asp:postbacktrigger controlid=”yourControl” /> and <asp:asyncpostbacktrigger controlid=”yourControl” eventname=”yourEvent” />. If you don’t supply either of these, your update panel automatically assumes that all controls within it are the latter. However, sometimes you need to designate a control to do a full page postback. For instance, file uploading won’t work using AJAX (unless you use some crazy IFrame methods), so you will have to set whichever button you use to submit your file to trigger a full page postback (<triggers><asp:postbacktrigger controlid=”yourFileUploadControl” /></trigger> <contenttemplate>…</contenttemplate>).
If you have any other ASP.NET AJAX tips, please post them here!
RSS Feed
Hey man
nice introduction to asp.net AJax this is exactly what I was looking for.
I’m a asp.net and Javascript developer, before asp.net ajax was introduced, I always hand write AJAX code with asp.net.
Now this new thing sounds exciting, but I’ve always wondered about the extenability. Say I want to have some fancy effect using Prototype+Script.aculous.us library, or make my own js library. As far as i know you can’t do that in asp.net ajax.
Please let me know that I’m wrong because if I was wrong then my life would be much much easier using this ASP.net ajax.
BTW, I have add your entry to my fav :c)
Yonk –
Thanks for reading! I’m glad I’m a favorite
In my next post, (which may happen today, who knows) I will describe how you can add custom scripting. Basically, it’s so freaking easy.
[...] adding one timer to control multiple UpdatePanels? To do this, you will use a technique from my second post in this series about triggers. First, follow the steps above, except put your timer elsewhere on the page outside of your [...]
Pingback by ASP.NET and AJAX: So Freaking Easy (Part 4: Timers) « .NET Discussion | July 23, 2007 |
[...] in .NET 2.0. Also, if your FileUpload control is on an AJAX-ified page, you will need to do some trigger fixes, since you can’t upload a file using AJAX, at least not yet (easily). Lastly, you need to [...]
Pingback by ASP.NET: Restrict Dimensions While Uploading Images With The FileUpload Control « .NET Discussion | November 27, 2007 |
[...] with for this rare error is to wrap your content (on your .aspx page) with another UpdatePanel and set your triggers to post back when the button is pressed. While the client may have to suffer another postback, [...]
Pingback by ASP.NET and AJAX: Error Making Forms Visible With UpdatePanel « .NET Discussion | February 29, 2008 |
Thanks!,