Click here to Skip to main content
6,822,613 members and growing! (19,639 online)
Email Password   helpLost your password?
Web Development » Ajax and Atlas » General     Intermediate License: The Code Project Open License (CPOL)

MagicAjax: Customising the "Loading..." Message

By radumi

An article about how to customise the MagicAjax default "Loading..." message
ASP.NET, Ajax, Dev
Posted:8 Jul 2008
Views:10,599
Bookmarked:21 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
19 votes for this article.
Popularity: 5.45 Rating: 4.26 out of 5
1 vote, 5.3%
1
1 vote, 5.3%
2
1 vote, 5.3%
3
1 vote, 5.3%
4
15 votes, 78.9%
5

Introduction

I needed to do what I say in the title and Googling this subject was not of great help, so here we are... I agree it may be obvious what to do but sometimes... under pressure... such an article may be of a great help.

Background

Basically, I see three most convenient ways to customise the MagicAjax library "Loading..." message:

  1. Hook into the library code... but better not only for such small customisation.
  2. Add in your page an HTML element having the name __AjaxCall_Wait that is expected by the library.
  3. Write an ASP.NET control that will render an HTML element having the name __AjaxCall_Wait (expected by the library).

Hook into the Library Code

I started with this because reading the library JavaScript is the way to understand what you need to do.

  • I used Lutz Roeder's Reflector to reverse the *.dll rather than downloading the opensource code because Reflector generates for you in one click all that you need to simply include the library project into a solution and play around with Visual Studio.

  • Reading the library JavaScript, I have seen the function:

    function CreateWaitElement() {
        var elem = document.getElementById('__AjaxCall_Wait');
        if (!elem) {
            elem = document.createElement("div");
            elem.id = '__AjaxCall_Wait';
            elem.style.position = 'absolute';
            elem.style.height = 17;
            elem.style.paddingLeft = "3px";
            elem.style.paddingRight = "3px";
            elem.style.fontSize = "11px";
            elem.style.fontFamily = 'Arial, Verdana, Tahoma';
            elem.style.border = "#000000 1px solid";
            elem.style.backgroundColor = "DimGray";
            elem.style.color = "#ffffff";
            elem.innerHTML = 'Loading ...';
            elem.style.visibility = 'hidden';
            document.body.insertBefore(elem, document.body.firstChild);
        }
        waitElement = elem;
    }

    Of course you can hook into elem.innerHTML something like an img tag but it would not be such a great idea.

  • From now on it is clear that the library expects to find in the host page an HTML element called __AjaxCall_Wait, otherwise the element will be created automatically.

Add in your page an HTML element having the name __AjaxCall_Wait that is expected by the library.

Just hook an...

<asp:Image id="__AjaxCall_Wait" runat="server" ImageUrl="~/img/wait.gif"
style="position: absolute; visibility: hidden"></asp:Image> 

... between the body and the form.

Write an ASP.NET Control...

It would be a very simple control only to render the desired HTML element called __AjaxCall_Wait; place it again between page body and form tags. This approach is useful when you want to run some initialisation code in pages having all different base classes, etc. Just be aware that the HTML element rendered by the control will have the id as a concatenation between the ASP.NET control id in the page, an "_" and finally the id of the asp:Image inside the control.

So if the control is has id="__AjaxCall" on the page and the <asp:Image... has id="Wait" inside the control, you will finally get the right id="__AjaxCall_Wait" for the element rendered in the page HTML - as the library expects.

Hope this helps.

History

  • 5th July, 2008: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

radumi


Member
Software Developer
Occupation: Software Developer
Location: New Zealand New Zealand

Other popular Ajax and Atlas articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
Generalvery useful information Pinmemberchenpengli9:26 26 Jun '09  
Generalabout the asp:Image control Pinmemberericpxz17:21 6 Nov '08  
GeneralSimple Alternative Solution PinmemberSurendra Sambana5:05 8 Jul '08  
GeneralRe: Simple Alternative Solution PinmemberRadu D.2:58 9 Jul '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

PermaLink | Privacy | Terms of Use
Last Updated: 8 Jul 2008
Editor: Deeksha Shenoy
Copyright 2008 by radumi
Everything else Copyright © CodeProject, 1999-2010
Web10 | Advertise on the Code Project