Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Error event in UserControl

Reply
Thread Tools

Error event in UserControl

 
 
Marc
Guest
Posts: n/a
 
      03-31-2009
Dear all

I tried to use the usercontrol error event to catch errors. I realized that
it never gets fired - please check these resources:
http://weblogs.asp.net/vga/archive/2003/06/16/8748.asp
http://stackoverflow.com/questions/1...t-usercontrols
http://cwizo.blogspot.com/2006/09/us...ot-firing.html

These resources describe why the error event is not fireing. But I would
like to know a work around or a method how the error event of a usercontrol
gets fired in case of an error that is not handled.

Thanks in advance for your help,

Marc

--
Kind Regards,

Marc
 
Reply With Quote
 
 
 
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      04-01-2009
Hi Marc,

To do this we can manually catch each exception and trigger the Error
event. Below is the sample:

ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeBehind="WebUserControl1.ascx.cs"
Inherits="WebApplication1.WebUserControl1" %>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click
Me" />

ascx.cs:
namespace WebApplication1
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
try
{
throw new Exception("hello world!");
}
catch (Exception ex) {
this.OnError(new WebUserControlEventArgs() { Message =
ex.Message });
}
}
}
public class WebUserControlEventArgs : EventArgs {
public string Message { get; set; }
}
}

aspx:
<uc1:WebUserControl1 ID="WebUserControl11" runat="server"/>
aspx.cs:

namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
{
this.WebUserControl11.Error+=new
EventHandler(WebUserControl11_Error);
}

void WebUserControl11_Error(object sender, EventArgs e)
{

Response.Write("Exception is thrown in WebUserControl11");
}
}
}

In each event handler of web user control we can use a try..catch block to
wrap our code. And trigger the Error event in the catch block to notify the
Page that uses the web user control.

If you have additional questions please feel free to ask.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
http://www.velocityreviews.com/forums/(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



 
Reply With Quote
 
 
 
 
Allen Chen [MSFT]
Guest
Posts: n/a
 
      04-03-2009
Hi Marc,

Have you solved this issue?

Regards,
Allen Chen
Microsoft Online Support

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 1 12-11-2004 01:28 PM
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 0 12-10-2004 02:21 PM
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 0 12-10-2004 02:20 PM
Can we use a usercontrol inside a usercontrol Rajesh Tiwari ASP .Net 0 08-12-2003 03:56 PM
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack huobazi ASP .Net 1 07-03-2003 03:14 AM



Advertisments