C# 在页面上添加UserControl时获取运行时异常,但没有编译器错误

C# 在页面上添加UserControl时获取运行时异常,但没有编译器错误,c#,.net,asp.net,exception,C#,.net,Asp.net,Exception,引发了类型为“System.Web.HttpUnhandledException”的异常 Step into: Stepping over non-user code 'System.Web.UI.Control.OnLoad' Step into: Stepping over non-user code 'System.Web.UI.Control.LoadRecursive' Step into: Stepping over non-user code 'System.Web.UI.Cont

引发了类型为“System.Web.HttpUnhandledException”的异常

Step into: Stepping over non-user code 'System.Web.UI.Control.OnLoad'
Step into: Stepping over non-user code 'System.Web.UI.Control.LoadRecursive'
Step into: Stepping over non-user code 'System.Web.UI.Control.LoadRecursive'
Step into: Stepping over non-user code 'System.Web.UI.Control.LoadRecursive'
Step into: Stepping over non-user code 'System.Web.UI.Page.ProcessRequestMain'
Step into: Stepping over non-user code 'System.Web.UI.Page.ProcessRequest'
Step into: Stepping over non-user code 'System.Web.UI.Page.ProcessRequest'
Step into: Stepping over non-user code 'System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute'
Step into: Stepping over non-user code 'System.Web.HttpApplication.ExecuteStep'
A first chance exception of type 'System.NullReferenceException' occurred in App_Code.2x2ldwnl.dll
A first chance exception of type 'System.Exception' occurred in App_Code.2x2ldwnl.dll
A first chance exception of type 'System.ServiceModel.CommunicationException' occurred in mscorlib.dll
A first chance exception of type 'System.NullReferenceException' occurred in App_Code.2x2ldwnl.dll
A first chance exception of type 'System.Exception' occurred in App_Code.2x2ldwnl.dll
我的Usercontrol在自己构建的时候也可以很好地编译。所有的构建都很好,但在我运行调试演练时崩溃。 你知道这是什么原因吗

用户控制代码:

Call Function
protected void DisplaySendMessageQuestion(string title, int messageType)
{
    UCResetPasswordDisplay.SetVisible(true);
    UCResetPasswordDisplay.MessageType = messageType.ToString();
    UCResetPasswordDisplay.Title = title;
}
用户控制aspx.cs

public partial class UserControls__ResetPasswordPopup : System.Web.UI.UserControl
{
    public event EventHandler YesResetClick;
    public event EventHandler NoResetClick;


protected void Page_Load(object sender, EventArgs e)
{
    PnlAddConfirmation.CssClass = "PanelResetPass";
    PnlAddConfirmation.CssClass = "PanelYesNoCore";
    txtUsername.Focus();
}

public string MessageType
{
    get { return this.lblMessageType.Text; }
    set { this.lblMessageType.Text = value; }
}

public string UserData
{
    get { return this.txtUsername.Text; }
    set { this.txtUsername.Text = value; }
}

public string Title
{
    get { return this.lblEventTitle.Text; }
    set { this.lblEventTitle.Text = value; }
}

public bool IsVisible
{
    get { return this.PnlAddConfirmation.Visible; }
    set { this.PnlAddConfirmation.Visible = value; }
}

public string ErrorMessage
{
    get { return this.LblEventNotification.Text; }
    set { this.LblEventNotification.Text = value; }
}

public void SetVisible(bool Visible)
{
    PnlAddConfirmation.Visible = Visible;
  //  PnlScreenCover.Visible = Visible;
}

protected void ChangePasswordButton_Click(object sender, EventArgs e)
{
    if (YesResetClick != null)
    {
        YesResetClick(this, EventArgs.Empty);
    }
}
protected void ImgBtnCancel_Click(object sender, EventArgs e)
{
    if (NoResetClick != null)
    {
          NoResetClick(this, EventArgs.Empty);
        }
    }
}

根据您发布的代码-以下之一必须为真:

  • PnlAddConfirmation
    为空
  • txtUsername
    为空
由于在OnLoad方法中抛出了
NullReferenceException
,因此您的控件的页面加载处理程序

您可以做的一件事是在VS中启用所有异常的中断-打开菜单:Debug->exceptions。在下面显示的对话框中,确保勾选了“抛出”复选框


附加了调试器后,您应该直接被发送到发生错误的代码行。请确保您的web.config也设置了
,否则您将没有必要的符号使其正常工作。

这是一个指向验证更改的文本框名称的验证程序控件。 即使在您建议的调试模式下,调试器也没有注意到它。 我把整个事情转移到一个干净的项目中,调试器终于注意到了这一点


我是ragin,我的工作需要升级到vs2010,并且有一个更不迟钝的VS调试器,一个拼写错误的名字应该作为一个错误被注意到,这是最常见的人为错误之一。

发布代码会有所帮助。请问您在页面生命周期的哪个阶段添加控件?Usercontrol中有哪些内容?似乎Usercontrol的内容会出错编译器只会捕获编译时错误,而不是运行时错误。Bump添加了代码,我只想将一个文本框中的输入返回到调用Usercontrol的页面,但我甚至无法加载Usercontrol。