2013-07-12 67 views
0

因此,这里是情节 我有一个加载一些数据的web部件。 我在页面的另一个地方有一个按钮,打开一个弹出窗口,当用户在该页面中执行某些操作时(创建操作),弹出窗口关闭并重新调用页面。在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>"); 

回答

0

这里的诀窍是loadgrid数据必须在OnPreRender中执行。

相关问题