Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:26:06+00:00 2026-05-24T10:26:06+00:00

My web forms inherits a class called MyPageMain , which inhertis System.Web.UI.Page and is

  • 0

My web forms inherits a class called MyPageMain, which inhertis System.Web.UI.Page and is located on the App_Code folder.

In this MyPageMain class I created this method, to record and output Exceptions (error messages):

public string Error(Exception pException, string pFriendlyMessage)
{
    using (BusError erro = new BusError())
    {
        int? errorId = //HERE Routine to log the error;

        StringWriter stringWriter = new StringWriter();

        using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
        {

            writer.AddAttribute(HtmlTextWriterAttribute.Class, "erroMain");
            writer.RenderBeginTag(HtmlTextWriterTag.Div); //<div>

            writer.RenderBeginTag(HtmlTextWriterTag.P); //<p>
            writer.Write(pFriendlyMessage);
            writer.RenderEndTag(); // </p>
            writer.RenderBeginTag(HtmlTextWriterTag.Small); 
            writer.Write("Event tracker:");
            writer.Write(errorId);
            writer.RenderEndTag(); 

            writer.RenderEndTag(); // </div>
            Console.WriteLine(stringWriter.ToString());
        }

    }
}

Then, when there is some exception on the page, I call it, like this:

    Protected void btnLoad_Click(object sender, EventArgs e)
    {
         LoadData();
    }        

    private void LoadData()
    {
        try
        {
             //Loading some data here.
        }
        catch (Exception ex)
        {
             Error(ex, "Unexpected error trying to load data.");
        }
    }

This is bulding OK, but doesn’t work… I think that one of the reasons may be the fact that the whole thing is inside an UpdatePanel. Any suggestions on how to make this work?

Is this Console.Writeline suitable for what i’m trying to do? Is this going to work on UpdatePanels?

Already Tried with Response.Write(...) and it does work. But not inside an UpdatePanel

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:26:09+00:00Added an answer on May 24, 2026 at 10:26 am

    When you use an UpdatePanel, you can only update content within the panel during an async postback triggered from that panel, so your error message will have to appear somewhere within the UpdatePanel. (That is, unless you set UpdateMode="Always" on one of your UpdatePanels, then its content is updated on every async and full postback. But that doesn’t help you here unless you put your error message in its own UpdatePanel with UpdateMode="Always", which would require you to add said UpdatePanel to every page. I understand this is not what you want to do.)

    The following example will work to add the error message at the top of the UpdatePanel.

    You will need to add a Control errorParent parameter to your Error method, so it can add the error message as child control to that parent control.

    In your catch block, just pass in whatever container control where you want the error message to appear. That control must be a container to accept child controls, so it has to be something that renders as a <div> or <span> tag, like an asp:Panel or asp:UpdatePanel.

    In the example below, you could use errorParent.Controls.Add(errorControl) to show the error message at the bottom of the UpdatePanel, or use AddAt() with a different index. Just be sure that index will always work on every page.

    Take a parent control and add a new Literal child control:

    public string Error(Exception pException, string pFriendlyMessage, Control errorParent)
    {
        using (BusError erro = new BusError())
        {
            int? errorId = //HERE Routine to log the error;
    
            Literal errorControl = new Literal();
            errorControl.Text = String.Format("<div class=\"errorMain\"><p>{0}</p><small>Event Tracker: {1}</small></div>", pFriendlyMessage, errorId);
            errorParent.Controls.AddAt(0, errorControl);
        }
    }
    

    Pass in the parent control:

    private void LoadData()
    {
        try
        {
             //Loading some data here.
        }
        catch (Exception ex)
        {
             Error(ex, "Unexpected error trying to load data.", MyUpdatePanel.ContentTemplateContainer);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which inherits System.Windows.Forms.Form. I need to make the form available
I have a web form page Default.aspx, which inherits from a BasePage class that
When creating a new web form the default page class is System.Web.UI.Page. Can this
I have web forms page that has 2 controls. A gridview and an associated
I am using ASP.NET Web Forms/C# . I am having this function in my
I have an entity class called catObras, and it inherits from the class NSManagedObject.
1)I have the PageBase class that inherits from Page Class. The all code behind
I've got a Windows Forms Button on a Form which submits a web request.
i created a simple advanced search page for web application, i thought sharing it
I am following this Asp .Net tutorial as a guide: http://www.asp.net/web-forms/tutorials/continuing-with-ef/using-the-entity-framework-and-the-objectdatasource-control-part-2-adding-a-business-logic-layer-and-unit-tests I have created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.