Page.PreviousPage.Master执行母版页而不是获取其值

时间:2013-10-17 15:05:55

标签: c# asp.net gridview master-pages

每次我使用this.Page.PreviousPage和anythig就像thisPage.PreviousPage一样,它似乎执行页面而不是获取它的值。

我告诉这个,因为,无论何时我在代码上使用它,它都会将我重定向到我在Masterage.aspx.cs文件中设置的错误页面,该页面对用户可以访问的页面执行此操作。它只发生在这些行上,因为当我运行断点时,程序会重定向到这些行上的错误页面。

        if (this.Page.PreviousPage != null) //This checks if the previous page is not empty
        {
            GridView gridViewToExport = new GridView();
            string gridViewName = Request.QueryString["gridviewname"];

            //Check if the masterpage contentplaceholder exists
            if (this.Page.PreviousPage.Master.FindControl("CPH1") != null)
            {
                //If Exists then do this steps
                Control ContentPlaceHolder1 = this.Page.PreviousPage.Master.FindControl("CPH1");
                gridViewToExport = (GridView)ContentPlaceHolder1.FindControl(gridViewName);
            }
            else
            {
                //If is not existent, then continue with this.
                gridViewToExport = (GridView)this.Page.PreviousPage.FindControl(gridViewName);
            }

            frmExportarDatos.EnableViewState = false;
            frmExportarDatos.Controls.Add(gridViewToExport);
        }

我从这里得到的错误是'this.Page.PreviousPage'抛出类型'System.Threading.ThreadAbortException'的异常'System.Web.UI.Page {System.Threading.ThreadAbortException}

1 个答案:

答案 0 :(得分:0)

您只需在此处添加支票

if(Page.PreviousPage.Master ==  null)
  //Some code.
else
  //Again some code.