|
|
|
|
|
Home
»
AJAX
»
Ajax with Postback Ritalin
|
|
|
|
Total page views :
7885
|
|
Total downloads :
|
|
|
|
|
|
|
Similar ArticlesMost ReadTop RatedLatest
|
|
|
|
|
|
|
|
|
|
Recently I noticed a simple and nice control giving more functionality to partial postback, it is Postback Ritalin. This is built on top of ASP.NET Ajax extensions and offers a nice solution to a common problem i.e. disabling button during partial postbacks. Let's explore bit more with an example:
Problem
Consider an Enrollment System for an institute. Enquiries come to institute for various courses, some of them enrolled in the institute first time itself and some goes to database just as an enquiry. The user (receptionist) needs to record both (enquiry & enrollment). While enrollment, system also needs to show when the last time person was enrolled, this should be shown on the screen goes to database as this information useful and need to be available all the time.
Solution
Let's create a web application as it should be accessible from outside of intranet. We will make this with the help of UpdatePanel and Postback Ritalin. This application needs two sections Enquiry and Enrollment (see picture below). Based on outcome of the enquiry details will be entered in the required section.
 When a user saves an enrollment, date and time will show-up on top of the screen:

If user is saving an enquiry only Enquiry panel should be updated, no need to refresh other parts of the page. Also we need to make sure that user doesn't press Save twice (while save operation is in-progress). So we will use UpdatePanel for partial rendering and Postback Ritalin for disabling the button with appropriate text.
Shown below screenshot showing partial update. Please note Save button is disabled while system saving the details and showing label as "Saving Enquiry..."

Implementation
In order to implement, first step should be to add a reference to PostBackRitalin assembly to your ASP.NET Web Application Project. You need to download this control first:

Below is the aspx page where Enquiry section is implemented with UpdatePanel:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Ritalin_Ajax_Implementation._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body> <form id="form1" runat="server"> <table> <tr> <td> <asp:ScriptManager ID="ScriptManager1" runat="server"/> <asp:Panel ID = "pnlEnquiry" GroupingText="Enquiry" runat="server"> <asp:UpdatePanel ID="UpdatePanelEnquiry" runat="server"> <ContentTemplate> Enquiry Name :   <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br/> <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" /> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> </td> <tr> <td> <asp:Panel ID="pnlEnrollment" GroupingText="Enrollment" runat="server"> <br/> <br/> Enrolled Student Name   <asp:TextBox ID="txtStudent" runat="server"></asp:TextBox><br/><br /> Enrolled Date Time <asp:TextBox ID="txtDate" runat="server"></asp:TextBox><br/> <asp:Button ID="Button2" runat="server" Text="Save Enrollment" OnClick="btnEnrollment_OnClick" /> <asp:Button ID="btnEnrollment" runat="server" Text="Refresh" /> </asp:Panel> </td> </tr> </tr> </table> </form> </body> </html>
Now all we need is to control the Save button during wait mode. We will use Encosia namespace for accessing Postback Ritalin library and obtain the desired functionality. Create an instance of MontoredUpdatePanel and assign "updatePanelEnquiry" to it. Finally we will add Postback Ritalin control and attach newly created instance of MonitoredUpdatePanel. This can be done on the aspx page or in code behind. We will put this in code behind (.cs) to make it flexible:
protected override void OnPreRender(EventArgs e) { MonitoredUpdatePanel enquiryPanel = new MonitoredUpdatePanel(); enquiryPanel.UpdatePanelID = "updatePanelEnquiry"; Encosia.PostBackRitalin pbrControl = new Encosia.PostBackRitalin(); pbrControl.WaitText = "Saving Enquiry..."; pbrControl.MonitoredUpdatePanels.Add(enquiryPanel); this.Controls.Add(pbrControl); }
Below are the contents of .cs file:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Encosia; // This is Postback Ritalin
using System.Threading;
namespace Ritalin_Ajax_Implementation
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
Thread.Sleep(2000); // This is where we can save to database, for now just using sleep.
txtName.Text = "";
}
protected void btnEnrollment_OnClick(object sender, EventArgs e)
{
Response.Write("Last Enrolled Time: " + DateTime.Now.ToString());
}
protected override void OnPreRender(EventArgs e)
{
MonitoredUpdatePanel enquiryPanel = new MonitoredUpdatePanel();
enquiryPanel.UpdatePanelID = "updatePanelEnquiry"; //Attaching UpdatePanel to be monitored
Encosia.PostBackRitalin pbrControl = new Encosia.PostBackRitalin();
pbrControl.WaitText = "Saving Enquiry...";
pbrControl.MonitoredUpdatePanels.Add(enquiryPanel);
this.Controls.Add(pbrControl); //Adding Postback Ritalin to the page
}
}
}
Postback Ritalin also has a property WaitImage to specify alternate image during partial postback. Isn't this simple and nice!
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
Rohit Sinha
An Ex-Microsoft employee, Master of Science in Computer Science and
PMP. Presently working as Product Manager and responsible for handling
multiple accounts/projects both on technical and functional side.
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Go.NET
Build custom interactive diagrams, network, workflow editors, flowcharts, or software design tools. Includes many predefined kinds of nodes, links, and basic shapes. Supports layers, scrolling, zooming, selection, drag-and-drop, clipboard, in-place editing, tooltips, grids, printing, overview window, palette. 100% implemented in C# as a managed .NET Control. Document/View/Tool architecture with many properties&events. Optional automatic layout.
|
Dundas Software
Dundas Chart for .NET is the most advanced .NET charting package available today. With an extremely complete feature set, elegant architecture and easy implementation, Dundas Chart can quickly add advanced Charting functionality to enhance and transform ASP.NET and Windows Forms applications. Whether you are implementing charting into internal projects, or building applications for clients, Dundas Chart offers advanced technology and advanced results to get the most out of data.
|
Clickatell's SMS Gateway
Clickatell's Developer Solutions allow you to SMS enable any website or
application via a range of API's. Learn More about our API connections.
|
Microsoft Visual Studio 2010 Professional
Microsoft Visual Studio 2010 Professional will launch on April 12, but you can beat the rush and secure your copy today by pre-ordering at the affordable estimated retail price of $549 (US). Pre-order now.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
Developer-Ready ASP.NET 2.0 Web Hosting with 3 MONTHS FREE
Now supporting .NET 3.0 Framework with Windows Workflow Foundation, Windows Communication Foundation (WCF), Windows Presentation Foundation (WPF), windows CardSpace (WCS)! Providing more flexibility for Developers with Web Services Support and a User/Permission Manger. Also supporting MS SQL 2005/2000 with Real-Time Backups, FREE Automated Attach .MDF Tool, FREE SQL Restore and Shrink SQL DB Tools, and SQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|