开发者

Getting a runtime exception when I add a UserControl on a page, but there are no compiler errors

Exception of type 'System.Web.HttpUnhandledException' was thrown.

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

My Usercontrol also compiles fine when built on its own eveything builds fine but then crash when i run debug walkthrough. any ideas what might be causing this ?

Usercontrol code:

Call Function
protected void DisplaySendMessageQuestion(string title, int messageType)
{
    UCResetPasswordDisplay.SetVisible(true);
    UCResetPasswordDisplay.MessageType = messageType.ToString();
    UCResetPasswordDisplay.Title = title;
}

User Control 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);
        }
    }
}


Based on the code you have posted - one of the following must be true:

  • PnlAddConfirmation is null
  • txtUsername is null

Since the NullReferenceException is being thrown in the OnLoad method - and therefore your control's Page_Load handler.

One thing you can do is to enable break on all exceptions in VS - Open the menu: Debug -> Exceptions. In the dialog that is shown (below) make sure that the 'Thrown' checkbox is ticked.

Getting a runtime exception when I add a UserControl on a page, but there are no compiler errors

With the debugger attached, you should get sent directly to the line of code where the error is occurring. Make sure your web.config has <compilation mode="debug"> set too, otherwise you won't have the necessary symbols for this to work correctly.


It was a validator Control pointing to validate a changed textbox name. even in debug mode as you have suggested the debugger failed to notice it. I moved the whole thing to a clean project and the debugger finally noticed it.

I was ragin, my work needs to upgrade to vs2010 and have a more less retarded VS debugger, a misspelt name should noticed as an error, being one of the most common human mistakes and all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜