0

所以,这是我有一个加载一些数据的 web 部件的场景。我在页面的另一个地方有一个按钮,它打开一个弹出窗口,当用户在该页面中执行某些操作(创建操作)时,弹出窗口关闭并重新加载调用页面。

发生这种情况时,我可以在浏览器中看到页面已重新加载,但我的新数据未显示在 Web 部件上。

我在创建子控件中绑定数据,我试图在页面加载中这样做,但它不起作用。如果我将光标放在地址栏上,它会显示新数据,但如果我按 F5 则不会。

 public class LastCreatedJobs : WebPart
    {
        private GridView _lastCreatedJobsGrid;

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            CreateGridControl();
        }

        private void CreateGridControl()
        {
            try
            {
                _lastCreatedJobsGrid = new GridView();
                _lastCreatedJobsGrid.RowDataBound += _lastCreatedJobsGrid_RowDataBound;

                var bJobCode = new BoundField { DataField = "JobCode", HeaderText = "Job Code" };
                bJobCode.ItemStyle.CssClass = "ms-cellstyle ms-vb2";
                bJobCode.HeaderStyle.CssClass = "ms-vh2";
                _lastCreatedJobsGrid.Columns.Add(bJobCode);

                var jobName = new HyperLinkField
                {
                    DataNavigateUrlFields = new[] { "JobWebsite" },
                    HeaderText = "Job Name",
                    DataTextField = "JobName"
                };
                jobName.ItemStyle.CssClass = "la";
                jobName.HeaderStyle.CssClass = "ms-vh2";
                jobName.ControlStyle.CssClass = "ms-listlink";
                _lastCreatedJobsGrid.Columns.Add(jobName);

                var biPowerLink = new HyperLinkField
                {
                    Target = "_blank",
                    DataNavigateUrlFields = new[] { "IPowerLink" },
                    HeaderText = "iP Link",
                    Text = @"<img src='" + ResolveUrl("/_layouts/15/PWC/DMS/Images/iclient.gif") + "' /> "
                };
                biPowerLink.ItemStyle.CssClass = "ms-cellstyle ms-vb-icon";
                biPowerLink.HeaderStyle.CssClass = "ms-vh2";
                _lastCreatedJobsGrid.Columns.Add(biPowerLink);

                _lastCreatedJobsGrid.CssClass = "ms-listviewtable"; //Table tag?
                _lastCreatedJobsGrid.HeaderStyle.CssClass = "ms-viewheadertr ms-vhlt";
                _lastCreatedJobsGrid.RowStyle.CssClass = "ms-itmHoverEnabled ms-itmhover";

                _lastCreatedJobsGrid.AutoGenerateColumns = false;

                _lastCreatedJobsGrid.EmptyDataText = Constants.Messages.NoJobsFound;

                Controls.Add(_lastCreatedJobsGrid);
                LoadGridData();
            }
            catch (Exception ex)
            {
                LoggingService.LogError(LoggingCategory.Job, ex);
            }
        }

        private void _lastCreatedJobsGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    JobInfo jobInfo = (JobInfo)e.Row.DataItem;

                    if (jobInfo.IsConfidential)
                    {
                        var newHyperLink = new HyperLink
                        {
                            Text = @"<img src='" + ResolveUrl("/_layouts/15/PWC/DMS/Images/spy-icon.gif") + "' /> ",
                            NavigateUrl = jobInfo.xlink
                        };
                        e.Row.Cells[2].Controls.RemoveAt(0);
                        e.Row.Cells[2].Controls.Add(newHyperLink);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingService.LogError(LoggingCategory.Job, ex);
            }
        }

        #region Private methods

        private void LoadGridData()
        {
            try
            {
                String currentUrl = SPContext.Current.Site.Url;

                var jobInfoList = new List<JobInfo>();

                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    using (var clientSiteCollection = new SPSite(currentUrl))
                    {
                        foreach (
                            SPWeb web in
                                clientSiteCollection.AllWebs.Where(
                                    c =>
                                    c.AllProperties[Constants.WebProperties.General.WebTemplate] != null &&
                                    c.AllProperties[Constants.WebProperties.General.WebTemplate].ToString() ==
                                    Constants.WebTemplates.JobWebPropertyName).OrderByDescending(d => d.Created).Take(5)
                            )
                        {
                            SPList jobInfoListSp = web.Lists.TryGetList(Constants.Lists.JobInfoName);
                            if (jobInfoListSp != null)
                            {
                                if (jobInfoListSp.Items.Count > 0)
                                {
                                    var value =
                                        new SPFieldUrlValue(
                                            jobInfoListSp.Items[0][Constants.FieldNames.Job.iPowerLink].ToString());

                                    jobInfoList.Add(new JobInfo
                                    {
                                        JobName = jobInfoListSp.Items[0][Constants.FieldNames.Job.JobName].ToString(),
                                        JobCode = jobInfoListSp.Items[0][Constants.FieldNames.Job.JobCode].ToString(),
                                        xlink= value.Url,
                                        JobWebsite = web.Url,
                                        IsConfidential = HelperFunctions.ConvertToBoolean(jobInfoListSp.Items[0][Constants.FieldNames.Job.Confidential].ToString())
                                    });
                                }
                            }

                            web.Dispose();
                        }
                    }
                });

                _lastCreatedJobsGrid.DataSource = jobInfoList;
                _lastCreatedJobsGrid.DataBind();
            }
            catch (Exception ex)
            {
                LoggingService.LogError(LoggingCategory.Job, ex);
            }
        }

        #endregion
    }

以及打开弹出窗口的页面:

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <SharePoint:ScriptLink ID="ScriptLink1" runat="server" Name="sp.js" OnDemand="false" Localizable="false" LoadAfterUI="true"/>
    <script type="text/javascript">
        //Just an override from the ClientField.js - Nothing Special to do here
        function DisableClientValidateButton() {
        }

        function waitMessage() {
            window.parent.eval("window.waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Creating Job','Working on the Job site.  Please wait.',90,450);");
        }

    </script>
</asp:Content>

以及该页面背后的代码,在按钮单击中,只是单击按钮后的重要部分。

  ClientScript.RegisterStartupScript(GetType(), "CloseWaitDialog",
                                               @"<script language='javascript'>
                        if (window.frameElement != null) {
                            if (window.parent.waitDialog != null) {
window.parent.waitDialog.close();                                
window.frameElement.commonModalDialogClose(1, 'New call was successfully logged.');

                            }
                        }
                        </script>");
4

1 回答 1

0

这里的技巧是加载网格数据必须在 OnPreRender 中执行。

于 2013-07-12T07:08:26.377 回答