Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Discover the top 5 tips for understanding .NET Interop
Search :       Advanced Search »
Home » AJAX » Ajax with Postback Ritalin

Ajax with Postback Ritalin

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.

Page Views : 10937
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


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.

1.gif
When a user saves an enrollment, date and time will show-up on top of the screen:

2.gif

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..."

3.gif

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:

4.gif

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 : &nbsp 
                           <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&nbsp;&nbsp
                <asp:TextBox ID="txtStudent" runat="server"></asp:TextBox><br/><br />
                 Enrolled Date Time &nbsp;
               <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!

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
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.
Looking for C# Consulting?
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.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
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.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
good by Rekha On August 5, 2009
Hey Rohit.. good article
Reply | Email | Modify 
Re: good by Rohit On August 5, 2009
Thanks Rekha!
Reply | Email | Modify 
DevExpress Free UI Controls
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.