Click here to Skip to main content
11,719,185 members (85,903 online)
Click here to Skip to main content

ASP.NET Custom Control: WebRequestPanel

, 17 Nov 2006 CPOL 36.5K 505 26
Rate this:
Please Sign up or sign in to vote.
This is an article on an ASP.NET custom control to display any text (like "Loading...") when the page is requesting data from a web server.

Introduction

This is an ASP.NET custom control that displays a text and/or image when the browser is requesting data from the server. It has a lot of options to set backcolor, forecolor, font, position, etc. To use this control, all you have to do is drag drop this control onto the ASPX page in which you want to add this functionality.

Using the code

You can find some of the properties that are exposed in this control listed below. These doesn't include properties that are inherited from System.Web.UI.WebControls.WebControl.

Properties

  • Left - Left position of the control
  • Top - Top position of the control
  • StyleSheet - Stylesheet to use when a CSS class is provided
  • ContentType - Content type. It could be 'Text', 'Image', or 'Text N Image'; defaults to 'Text'
  • Text - Text to display, if content type is 'Text' or 'Text N Image'; defaults to 'Loading.....'
  • ImageURL - URL of the image to display, if content type is 'Image' or 'Text N Image'
  • DisplayWhenNewSession - This property tells whether to display the text when a new session is created; when it is set to false, it will not display the text when a new session has been created during the postback; if you get an HttpException (0x80004005), set this property to false; it defaults to false

Let us see an example

We will see two examples. One with backcolor, forecolor, etc., added to the control directly through its properties, and another with these things specified in a CssClass.

Example 1

In this example, all the backcolor, forecolor, font, etc., are defined through the properties exposed by the control.

Below is the HTML that you have to put in the ASPX page.

<cc1:WebRequestPanel id=WebRequestPanel1 
    Width="100px" Height="15px" Font-Size="Smaller" 
    Font-Names="Verdana" ForeColor="white" BackColor="red" 
    runat="server" Text=" Loading... "></cc1:WebRequestPanel>

The page with the above control is as below:

WebRequestPanel Control

Example 2

In this example, all the backcolor, forecolor, font, etc., are defined in a CssClass. You set the style sheet to use in the StyleSheet property so that the control knows which stylesheet to use. You might be wondering why you have to set the StyleSheet property. This is because the control flushes a table to the client during its Oninit; during this, the style sheet you had linked with the page would not be sent to the client so we have to send the style sheet to the client from the control.

Below is the HTML that you have to put in the ASPX page:

<cc1:WebRequestPanel Text=" Loading... " id="WebRequestPanel1" 
    runat="server" CssClass="WebRequestPanel" 
    StyleSheet="~/Style/StyleSheet.css"></cc1:WebRequestPanel>

The page with the above control is as below:

WebRequestPanel Control

Limitation

  1. You should not be using this control in pages where you might add or modify your HTTP response headers. If you modify or add any HTTP response header in your code, you will get an error saying "Server cannot append header after HTTP headers have been sent."

Points of interest

  1. If you get an Exception saying "Session state has created a session ID, but cannot save it because the response was already flushed by the application", then make sure you have set DisplayWhenNewSession to 'false'.
  2. If you want to set any property, set it in the HTML itself. Because the control's HTML would be flushed to the client before the page Init is called, which is the first chance you might get to change your properties.
  3. If you want to use this control in ASP.NET 1.1, all you have to do is download the source and copy WebRequestPanel.vb into a .NET 1.1 Class Library. Now add the required references and compile the class library.
  4. If you go to a page which doesn't have a WebRequestPanel from the page which has the WebRequestPanel, it will be visible in the redirected page too; to fix this problem, add the panel to the redirected page and set its DontDisplay property to true. Make sure you have the same name for the control as you had in the previous page.

History

  • 2006-08-24 (YYYY-MM-DD): Article created.
  • 2006-11-09 (YYYY-MM-DD): "Always Shows" issue fix.

License

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

Share

About the Author

Patrick.Alex
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
Generalmessing css Pin
GC9N29-Nov-07 9:50
memberGC9N29-Nov-07 9:50 
Generalwhen loading a page Pin
fahdansari17-Jun-07 22:26
memberfahdansari17-Jun-07 22:26 
GeneralRe: when loading a page [modified] Pin
Patrick.Alex18-Jun-07 8:56
memberPatrick.Alex18-Jun-07 8:56 
QuestionAlways show Pin
ildobarros5-Sep-06 8:43
memberildobarros5-Sep-06 8:43 
AnswerRe: Always show Pin
Patrick.Alex9-Sep-06 0:43
memberPatrick.Alex9-Sep-06 0:43 
QuestionRe: Always show Pin
SantiagoGuerra31-Oct-06 4:11
memberSantiagoGuerra31-Oct-06 4:11 
AnswerRe: Always show Pin
Patrick.Alex8-Nov-06 21:19
memberPatrick.Alex8-Nov-06 21:19 
GeneralShow error when using Pin
vik2028-Aug-06 1:42
membervik2028-Aug-06 1:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150901.1 | Last Updated 17 Nov 2006
Article Copyright 2006 by Patrick.Alex
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid