views:

151

answers:

2

Hi I have an ASP.NET(2.0, C#) web application, and I wanted to know how to display all the general errors that could occur on the master page using divs.

For example if there is an 'add new user' page, all the fields that had problems will be shown something like this:
The following Error(s) Occured:

  1. ...
  2. ...

I am using a master page, so I wanted to know how I could use a div in there, with a label maybe, to display errors from any of the content pages.

Thank you.

+5  A: 

I would recommend using a Panel.

<asp:Panel runat="server" id="pnlErrors" Visible="false">
The following Errors(s) Occurred: 
<asp:BulletedList id="lstErrors" runat="server">
</asp:BulletedList>
</asp:Panel>

Then just add the errors to lstErrors programmatically if they occur and set the visibility to true.

EDIT: I originally didn't read the part about the Master page. One issue you're probably going to run into is finding that control from your content page. Here is one way you can do so:

BulletedList lstReference = (BulletedList) this.Master.FindControl("lstErrors");
lstReference.Items.Add("Error occured contacting database.");
lstReference.Items.Add("Error occured processing payment.");

Panel panReference = (Panel) this.Master.FindControl("pnlErrors");
panReference.Visible = true;
regex
A: 

If you use in the built ValidationSummary control, you don't have to do anything other than put on on the Master page:

<div class="error">
  <asp:ValidationSummary ID="vldSummaryMaster" runat="server" />
</div>

This of course assumes that you are using the built in validation controls in order to capture errors.

John Rasch