按钮单击抛出nullReference异常

时间:2015-07-21 07:54:39

标签: c#

嗨,我是c#的新手,过去几天一直在研究这个项目。我发现其他问题与我的相似,但找不到解决方案。我有这个项目,其中有一个按钮(结束日操作)。单击该按钮会抛出nullReferenceException。

这是我的C#代码:

 protected void EndDayOperationButton_Click(object sender, EventArgs e)
    {
        var date = Conversion.TryCastDate(BodEngDateTextBox.Text);
        var userId = UserId;
        var isAdmin = Common.Helpers.SessionHelper.IsAdmin();

        if (!isAdmin)
        {
            ReturnButton.Visible = true;
            EndDayOperationButton.Visible = true;
            ShowFailModal("< b > Authorization Failed!</ b > < br /> Contact your system admin to perform day operation.");
            return;
        }

        if (!BusinessLayer.Security.Login.IsBoDStarted(date))
        {
            Response.Redirect("~/Utilities/BodOperation.aspx");
        }
        else
        {
            try
            {
                if (BusinessLayer.Utilities.DayOperation.EndDayOperation(date, OfficeId, userId))
                {
                    ReturnButton.Visible = true;
                    EndDayOperationButton.Visible = false;
                    ReturnButton.Visible = false;
                    ShowSuccessModal("<B>EOD Completed Successfully</B></br>You can now logout from the system.");
                }
                else
                {
                    ShowFailModal("<B>EOD Failed.</B></br>An unknown error occured during EOD operation.");
                }
            }
            catch (Exception Ex)
            {
                ShowFailModal("<B>EOD Failed.</B></br>" + Ex.Message);
            }
        }
    }

Page使用UserControl,这里有例外

 public Literal MessageLiteral => MessageLabel;

    public string Message
    {
        get { return MessageLabel.Text; }
        set {MessageLabel.Text = value; }
    }

堆栈追踪:

  

[NullReferenceException:对象引用未设置为的实例   一个东西。]          Everest.Net.Web.UserControls.MaskDialogControl.set_Message(字符串   价值)   d:\珠峰\ Everest.Net.Web \用户控件\ MaskDialogControl.ascx.cs:24          Everest.Net.Web.BaseObjects.EverestWebPage.ShowModal(String message)in   d:\珠峰\ Everest.Net.Web \ BaseObjects \ EverestWebPage.cs:82          Everest.Net.Web.BaseObjects.EverestWebPage.ShowFailModal(String message)in   d:\珠峰\ Everest.Net.Web \ BaseObjects \ EverestWebPage.cs:103          Everest.Net.Web.Utilities.EodOperation.EndDayOperationButton_Click(对象   发件人,EventArgs e)in   d:\珠峰\ Everest.Net.Web \公用\ EodOperation.aspx.cs:71          System.Web.UI.WebControls.Button.OnClick(EventArgs e)+11756692          System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)+149          System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)   3359

0 个答案:

没有答案