Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net custom control used in user control (ascx) - how to catch on load error?
    primarykey
    data
    text
    <p>I have a custom control that is placed on a user control(ascx). In the load of the custom control happens an error. I would like to "catch" this error in the user control(ascx). How could I do this?</p> <p>Default aspx:</p> <pre><code>&lt;%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %&gt; &lt;%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt;&lt;title&gt;&lt;/title&gt;&lt;/head&gt; &lt;body&gt;&lt;form id="form1" runat="server"&gt; &lt;asp:Label runat="server" ID="test" Text="hello world"&gt;&lt;/asp:Label&gt; &lt;uc1:WebUserControl1 ID="WebUserControl11" runat="server" /&gt; &lt;/form&gt;&lt;/body&gt;&lt;/html&gt; </code></pre> <p>WebUserControl1.ascx:</p> <pre><code>&lt;%@ Control Language="vb" AutoEventWireup="false" CodeBehind="WebUserControl1.ascx.vb" Inherits="WebApplication1.WebUserControl1" %&gt; &lt;%@ Register tagPrefix="test" namespace="WebApplication1" assembly="WebApplication1" %&gt; &lt;test:MyControl runat="server" ID="test2" Text="test"&gt;&lt;/test:MyControl&gt; </code></pre> <p>WebUserControl1.ascx.vb:</p> <pre><code>Public Class WebUserControl1 Inherits System.Web.UI.UserControl Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) Try 'Doesn't work! MyBase.OnLoad(e) Catch ex As Exception handleException(ex) End Try End Sub Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error 'Doesn't work! handleException(New Exception()) End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Private Sub handleException(ByVal ex As Exception) Me.Controls.Add(New LiteralControl("ex.tostring")) End Sub End Class </code></pre> <p>And last but not least: my custom control:</p> <p>MyControl.vb:</p> <pre><code>Public Class MyControl Inherits System.Web.UI.WebControls.Label Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) Throw New Exception("") MyBase.OnLoad(e) End Sub End Class </code></pre> <p>I would like to be able to catch this error, in the *.ascx file this seems not be possible? Or is it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload