473,811 Members | 2,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to catch an error from a ASCX control

I have a very simple test page that the only thing it does is render a
control.

This control generates and throws an error.

I need to catch the error on my ASPX page but I can't figure out where to
put my try/catch block to make it work.

Any ideas?

Thanks,
Fernando
Sep 6 '06 #1
2 1864
Hi,

Fernando Chilvarguer wrote:
I have a very simple test page that the only thing it does is render a
control.

This control generates and throws an error.

I need to catch the error on my ASPX page but I can't figure out where to
put my try/catch block to make it work.

Any ideas?

Thanks,
Fernando
Not tested: The controls are rendered in the Render method of the Page
class. In your own page, which is derived from the base Page class, you
should be able to do that:

protected override void Render( HtmlTextWriter writer )
{
try
{
base.Render( writer );
}
catch ( Exception ex )
{
// Deal with exception
}
}

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Sep 7 '06 #2
Hi Laurent,

I tried and it did not work.

By following your example, I tried to handle the exception by putting
similar code on Page_PreInit, Page_Init, Page_PreRender, Page_Load.

Nothing worked.

By stepping into the code, it seems that it was executed in the following
order:

WebPage PreInit, WebPage Init, Control Load (where I throw and exception).

The code still blows up with an "Unhandled Exception"

I guess I'm still confused with the lifecycle and what's calling what on
ASP.NET.
"Laurent Bugnion" <ga*********@bl uewin.chwrote in message
news:OY******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

Fernando Chilvarguer wrote:
>I have a very simple test page that the only thing it does is render a
control.

This control generates and throws an error.

I need to catch the error on my ASPX page but I can't figure out where to
put my try/catch block to make it work.

Any ideas?

Thanks,
Fernando

Not tested: The controls are rendered in the Render method of the Page
class. In your own page, which is derived from the base Page class, you
should be able to do that:

protected override void Render( HtmlTextWriter writer )
{
try
{
base.Render( writer );
}
catch ( Exception ex )
{
// Deal with exception
}
}

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Sep 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2581
by: Josema | last post by:
Hi to all, I have a webform.aspx and inside i have a dropdown list with autopostback and a place holder... Depending of the selected index that the user selects in the dropdownlist i load a usercontrol into the place holder... i dont know why im getting this error:
1
1963
by: Gaffar | last post by:
Hello I am Getting the following error: please resolve this. Thnaks in advance Regards Gaffar. Server Error in '/AdHoc' Application. -------------------------------------------------------------------------------- Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser...
1
3026
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have access to the methods and properties from the Page_Load, no problem there. But as soon as I want access to the user control from another procedure on the same page, I get the next error message: "Object reference not set to an instance of an...
6
6128
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page then tried to access 2nd, or 3rd, etc page. The problem is it happens sometimes - sometimes when they clicked refresh button, then everything is ok. Now they told me it happens more frequently. but I have tried by myself many times and never got...
5
1841
by: Patrick | last post by:
I understand it is built in behaviour that if an ASP.NET's web.config is set to: <customErrors mode="RemoteOnly" /> then I only get a detailed error message on screen when the ASP.NET application is executed on the IIS server itself. However, I note that with the following
4
1977
by: rushikesh.joshi | last post by:
Hi All, I have created my own WebControl and want to add it in my aspx page at runtime. it's compiling perfectly, but when i m going to execute, it gives me error of "Object reference not set to an instance of an object." in my server control (ascx.cs file)
1
2062
by: Larry Epn | last post by:
I've created a project from Microsoft's "club.vsi". I don't want inline code so I've separated all aspx and ascx pages into code-behind pages. I'm compiling the project and continue to get this error: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl). It is referring to "LoginBanner" on the first line of the code below. public...
1
2583
by: James Geurts | last post by:
I'm having some major problems trying to get a user control working in asp.net 2.0. I have a user control in a sub directory of my project and I'm attempting to put it on an aspx page. I'm getting an error like the following, though: The base class includes the field 'MyUserControl', but its type (Controls.MySubControls.MyUserControl) is not compatible with the type of control (ASP.controls_mysubcontrols_myusercontrol_ascx).
1
1753
by: Nathan Sokalski | last post by:
I am revieving the following error for one of my controls when loading any pages that use it: Server Error in '/exposure/app' Application. -------------------------------------------------------------------------------- Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
0
9728
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10648
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10402
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.