• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

Dynamic ASP.NET-WebControls using Ajax.NET ...

The concept

The idea is to load dynamic content into a part of a webpage. With ASP.NET this can be done loading and assigning WebControls to a container - like a PlaceHolder-control. The problem with this approach is that the assignment occurs on the server-side and the page has to be fully reloaded to display the changed content. This is not very nice for the user is eye and costs performance, because superfluous information is transported over the network. This is where we can use Ajax to reload only this part of the page that needs to be updated.

The example

The sample-project is very simple but you can use the same scenario for more advanced requirements as well. Here is the user-interface:


Figure 1

The DropDownList contains 3 values: Red, Blue, Green. For each colour exists a WebControl, that is loaded dynamically when the selection of the DropDownList changes. Therefore the property AutoPostBack of the DropDownList has to be set to true. In the eventhandler SelectedIndexChanged the associated control is loaded. To avoid a full reload of the page, the created WebControl is added to a PlaceHolder-control that is defined inside of an UpdatePanel:

<asp:UpdatePanel ID="updatePanel" runat="server"> <ContentTemplate> <asp:PlaceHolder ID="placeHolder" runat="server"></asp:PlaceHolder> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddColor" /> </Triggers> </asp:UpdatePanel>


protected void ddColor_SelectedIndexChanged(object sender, EventArgs e) { SetColor(); } private void SetColor() { Control c = Page.LoadControl(ddColor.SelectedValue + "Control.ascx"); placeHolder.Controls.Clear(); placeHolder.Controls.Add(c); }


The controls are loaded by their names which are constructed by a concatenation of the DropDownList is value and the suffix "Control.ascx". The DropDownList is registered as a Trigger for the UpdatePanel by adding it is ControlID to the list of Triggers in the UpdatePanel is markup. So, what is a Trigger? A Trigger is an ASP.NET-servercontrol like in our case a DropDownList that is introduced to an UpdatePanel as a source of an update. The controls that are placed inside of an UpdatePanel are automatically registered as Triggers, if the property ChildrenAsTriggers has the value true. Before we add the newly created WebControl to the PlaceHolder, we clear the PlaceHolder cause we want to display only one control.

More extended use-cases

For a real-life application you can use the same technique. Let is assume that we have an Rss-Feed that we want to display in different kind of view-modes. In one view-mode only the headings are displayed in a list. In another view-mode, the headings, the first 200 letters of the description and some information about the author are shown to the user. The view-mode could be selected by a DropDownList just like the one we used to choose the 3 colours. The Rss-Feeds could be displayed in 2 controls that are created dynamically.

Final thoughts

Ajax-techniques are very useful to refresh dedicated regions of a page for increasing the usability of a web-application and the performance. Analyse your pages with care to find the parts of it where you can use Ajax - the trick is to avoid overdose!

source: 123aspx

 Original Source:

AddThis Social Bookmark Button

Posted at 08:45:31 am | Permalink | Posted in .Net  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Top Stuff

MessengerFX

e-messenger

ILoveIM

Top 20 Ruby CMS

eBuddy

MSN Web Messenger



About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (164)
  • Ajax (82)
  • Ajax Games (10)
  • Articles (95)
  • Bookmarking (35)
  • Calendar (20)
  • Chat (45)
  • ColdFusion (3)
  • CSS (75)
  • Email (23)
  • Facebook (83)
  • Flash (19)
  • Google (54)
  • Html (27)
  • Image (11)
  • International Calls & VOIP (7)
  • Java (54)
  • Javascript (265)
  • jQuery (159)
  • JSON (61)
  • Perl (2)
  • PHP (156)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (8)
  • Ruby (31)
  • Storage (4)
  • Toolkits (103)
  • Tutorials (217)
  • UI (11)
  • Utilities (174)
  • Web2.0 (18)
  • XmlHttpRequest (28)
  • YUI (12)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange