Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 发布页面上出现奇怪问题并单击事件_C#_Asp.net_Post - Fatal编程技术网

C# 发布页面上出现奇怪问题并单击事件

C# 发布页面上出现奇怪问题并单击事件,c#,asp.net,post,C#,Asp.net,Post,我有一个为报告而设计的.aspx页面,上面有一个gridview加上两个按钮和两个日期值文本框。 我将一个按钮的代码包装在一个try-catch块中,这意味着如果在单击按钮后发生任何错误,那么应该处理该错误,它可以正常工作,但当我在文本框中输入总和值并单击按钮时,会发生以下错误: Server Error in '/' Application. ----------------------------------------------------------------------------

我有一个为报告而设计的.aspx页面,上面有一个gridview加上两个按钮和两个日期值文本框。 我将一个按钮的代码包装在一个try-catch块中,这意味着如果在单击按钮后发生任何错误,那么应该处理该错误,它可以正常工作,但当我在文本框中输入总和值并单击按钮时,会发生以下错误:

Server Error in '/' Application.
--------------------------------------------------------------------------------


Object reference not set to an instance of an object. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 



[NullReferenceException: Object reference not set to an instance of an object.]
   Pages_Admin_Report_New._btnReport_Click(Object sender, EventArgs e) +33120
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3803




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18045 
由于代码没有进入try-catch块,我真的不知道发生了什么,如果有任何帮助,我们将不胜感激

以下是页面加载代码:

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["UserId"] == null)
    {
        Response.Redirect("../../Default.aspx");
    }
    try
    {
        string currentPageFileName = new FileInfo(this.Request.Url.LocalPath).Name;
        if (!userIsAuthorised(Guid.Parse(Session["UserId"].ToString()), currentPageFileName))
        {
            Response.Redirect("../../Default.aspx");
        }
    }
    catch { Response.Redirect("../../Default.aspx"); }
}
以下是按钮单击事件代码:

protected void _btnReport_Click(object sender, EventArgs e)
{
    try
    {
     //My Code here
    }
    catch (Exception ex)
    {
        lblMessage.Text = "Error : " + ex.InnerException.Message;
    }
}
这是完整的.aspx代码

    <%@ Page Title="" Language="C#" MasterPageFile="~/Pages/Admin/SportMasterPage.master" AutoEventWireup="true" CodeFile="Report_New.aspx.cs" Inherits="Pages_Admin_Report_New" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../../Content/Style/StyleSheet.css" rel="stylesheet" type="text/css" />
    <script src="../../Content/Js/jquery.js" type="text/javascript"></script>
    <script src="../../Content/Js/jquery.maskedinput-1.3.js" type="text/javascript"></script>
    <script type='text/javascript'>
        jQuery(function ($) {
            $("#txtFromDate").mask("9999/99/99");
            $("#txtToDate").mask("9999/99/99");
        });
    </script>
    <script type="text/javascript">

        function PrintPanel() {

            var panel = document.getElementById("<%=pnlPrint.ClientID %>");

            var printWindow = window.open('', '', 'height=400,width=800');

            printWindow.document.write('<html><head><link href="../../Content/Style/StyleSheet.css" rel="stylesheet" type="text/css" /><title>DIV Contents</title>');

            printWindow.document.write('</head><body dir="rtl" >');

            printWindow.document.write(panel.innerHTML);

            printWindow.document.write('</body></html>');

            printWindow.document.close();

            setTimeout(function () {

                printWindow.print();

            }, 500);

            return false;

        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="frmData" class="MainPageData">
        <table>
            <tr>
                <td>
                    <div id="frmtitle">
                        آمار کلی ثبت نام</div>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblMessage" runat="server"></asp:Label>
                </td>
            </tr>
        </table>
        <hr class="frmborder" />
        <div class="space">
        </div>
        <table style="width: 100%">
            <tr style="width: 100%">
                <td style="width: 100%">
                    <table style="width: 100%">
                        <tr>
                            <td style="padding-right: 15px">
                                از :
                            </td>
                            <td>
                                <asp:TextBox ID="txtFromDate" runat="server" MaxLength="10" dir="ltr" Width="100px"
                                    class="validate[required] text-input" ClientIDMode="Static"></asp:TextBox>
                            </td>
                            <td style="padding-right: 15px">
                                تا :
                            </td>
                            <td>
                                <asp:TextBox ID="txtToDate" runat="server" MaxLength="10" dir="ltr" Width="100px"
                                    class="validate[required] text-input" ClientIDMode="Static"></asp:TextBox>
                            </td>
                            <td>
                                &nbsp;&nbsp;
                            </td>
                            <td style="padding-right: 15px">
                                &nbsp;
                            </td>
                            <td style="padding-right: 15px">
                                <asp:Button ID="_btnReport" runat="server" Text="تهییه گزارش" 
                                    onclick="_btnReport_Click"  />
                            </td>
                            <td>
                                <asp:Button ID="_btnReportToday" runat="server" Text="گزارش امروز" 
                                    onclick="_btnReportToday_Click"  />
                            </td>
                            <td>
                                <asp:ImageButton ID="btnPrint" runat="server" OnClientClick="PrintPanel(); return false;"
                                    ImageAlign="AbsMiddle" ImageUrl="~/Content/Image/print.png" ToolTip="چاپ" />
                            </td>
                        </tr>
                        <tr>
                            <td style="padding-right: 15px">
                                &nbsp;
                            </td>
                            <td>
                                &nbsp;
                            </td>
                            <td style="padding-right: 15px">
                                &nbsp;
                            </td>
                            <td>
                                &nbsp;
                            </td>
                            <td>
                                &nbsp;
                            </td>
                            <td style="padding-right: 15px">
                                &nbsp;
                            </td>
                            <td style="padding-right: 15px">
                                &nbsp;
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr style="width: 100%">
                <td style="width: 100%">
                    <asp:Panel ID="pnlPrint" runat="server">
                        <table style="width: 100%">
                            <tr style="width: 100%">
                                <td style="width: 100px" align="right" >
                                <img src="../../Content/Image/48x48.jpg"  />
                                </td>
                                <td   colspan="3"  align="center">
                                    <asp:Label ID="lblTitle" runat="server" Font-Names="Tahoma" Font-Size="16px"></asp:Label>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4">
                                    <br />
                                    <br />
                                </td>
                            </tr>
                            <tr style="width: 100%" dir="rtl">
                                <td style="text-align: center; width: 100px">
                                </td>
                                <td style="text-align: center; width: 100px">
                                    عضویتــ
                                </td>
                                <td style="text-align: center; width: 100px">
                                    پارکینگـ
                                </td>
                                <td style="text-align: center; width: 155px">
                                    خدمات
                                </td>
                            </tr>
                            <tr style="width: 100%">
                                <td style="width: 100%" colspan="4">
                                    <asp:GridView ID="_GVTotalRegistration" runat="server" CssClass="mGrid" AutoGenerateColumns="False">
                                        <Columns>
                                            <asp:TemplateField>
                                                <ItemTemplate>
                                                    <asp:HyperLink ID="linkReport" runat="server" Text='<%#Eval("RegisterType")%>' Target="_blank"
                                                        NavigateUrl='<%#Eval("Url")%>' Style="text-decoration: none"></asp:HyperLink>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="Total_Ozviat" HeaderText="کل" />
                                            <asp:BoundField DataField="Total_Ozviat_New" HeaderText="جدید" />
                                            <asp:BoundField DataField="Total_Ozviat_Old" HeaderText="قدیم" />
                                            <asp:BoundField DataField="Total_Ozviat_Men" HeaderText="مرد" />
                                            <asp:BoundField DataField="Total_Ozviat_Women" HeaderText="زن" />
                                            <asp:BoundField DataField="Total_Parking" HeaderText="کل" />
                                            <asp:BoundField DataField="Total_Parking_Men" HeaderText="مرد" />
                                            <asp:BoundField DataField="Total_Parking_Women" HeaderText="زن" />
                                            <asp:BoundField DataField="Total_Card_New" HeaderText="کارت جدید" />
                                            <asp:BoundField DataField="Total_Card_Replace" HeaderText="تعویض کارت" />
                                            <asp:BoundField DataField="Total_Card_Parking" HeaderText="پارکینگ" />
                                        </Columns>
                                        <RowStyle HorizontalAlign="Center" />
                                    </asp:GridView>
                                </td>
                            </tr>
                        </table>
                    </asp:Panel>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>

jQuery(函数($){
$(“#txtFromDate”).mask(“9999/99/99”);
$(“#txtToDate”).mask(“9999/99/99”);
});
函数PrintPanel(){
var panel=document.getElementById(“”);
var printWindow=window.open(“”,’高度=400,宽度=800’);
printWindow.document.write('DIV Contents');
printWindow.document.write(“”);
printWindow.document.write(panel.innerHTML);
printWindow.document.write(“”);
printWindow.document.close();
setTimeout(函数(){
printWindow.print();
}, 500);
返回false;
}
آمار کلی ثبت نام


عضویتــ پارکینگـ خدمات
处理程序中捕获的异常很可能没有任何内部异常,当您尝试访问内部异常的消息时,会抛出NullReference。您应该首先检查空值:

catch (Exception ex)
{
    if (ex.InnerException != null)
    {
        lblMessage.Text = "Error : " + ex.InnerException.Message;
    }
    else
    {
        lblMessage.Text = "Error : " + ex.Message;
    }
}

请显示与此特定错误相对应的代码。这将确保提供透视图答案更加容易。您可以从.aspx和codebehind?StackOverflow中获得一些代码吗?用户无法读取您的想法