C# 在Web部件生命周期中首次加载数据,但在弹出窗口中,重新加载不会刷新
这是场景 我有一个加载一些数据的Web部件。 我在页面的另一个地方有一个按钮,它打开一个弹出窗口,当用户在该页面中执行某些操作(创建操作)时,弹出窗口关闭,调用页面重新加载 发生这种情况时,我可以在浏览器中看到页面已重新加载,但我的新数据不会显示在Web部件上 我在创建子控件中绑定数据,我尝试在页面加载中绑定数据,但没有成功。 如果我把光标放在地址栏上,它会显示新的数据,但如果我按F5,它不会显示C# 在Web部件生命周期中首次加载数据,但在弹出窗口中,重新加载不会刷新,c#,javascript,sharepoint,web-parts,C#,Javascript,Sharepoint,Web Parts,这是场景 我有一个加载一些数据的Web部件。 我在页面的另一个地方有一个按钮,它打开一个弹出窗口,当用户在该页面中执行某些操作(创建操作)时,弹出窗口关闭,调用页面重新加载 发生这种情况时,我可以在浏览器中看到页面已重新加载,但我的新数据不会显示在Web部件上 我在创建子控件中绑定数据,我尝试在页面加载中绑定数据,但没有成功。 如果我把光标放在地址栏上,它会显示新的数据,但如果我按F5,它不会显示 public class LastCreatedJobs : WebPart {
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
}
public类LastCreatedJobs:WebPart
{
私有网格视图_lastCreatedJobGrid;
受保护的覆盖无效CreateChildControls()
{
base.CreateChildControls();
CreateGridControl();
}
私有void CreateGridControl()
{
尝试
{
_LastCreateDjobGrid=新建GridView();
_LastCreateDjobGrid.RowDataBound+=\u LastCreateDjobGrid\u RowDataBound;
var bJobCode=newboundfield{DataField=“JobCode”,HeaderText=“Job Code”};
bJobCode.ItemStyle.CssClass=“ms cellstyle ms-vb2”;
bJobCode.HeaderStyle.CssClass=“ms-vh2”;
_LastCreatedJobGrid.Columns.Add(bJobCode);
var jobName=新的超链接字段
{
DataNavigateUrlFields=new[]{“JobWebsite”},
HeaderText=“作业名称”,
DataTextField=“作业名”
};
jobName.ItemStyle.CssClass=“la”;
jobName.HeaderStyle.CssClass=“ms-vh2”;
jobName.ControlStyle.CssClass=“ms listlink”;
_LastCreatedJobGrid.Columns.Add(作业名);
var biPowerLink=新的超链接字段
{
Target=“_blank”,
DataNavigateUrlFields=new[]{“IPowerLink”},
HeaderText=“iP链接”,
Text=@“”
};
biPowerLink.ItemStyle.CssClass=“ms cellstyle ms vb图标”;
biPowerLink.HeaderStyle.CssClass=“ms-vh2”;
_LastCreatedJobGrid.Columns.Add(biPowerLink);
_lastCreateDjobGrid.CssClass=“ms listviewtable”//表标记?
_lastCreateDjobGrid.HeaderStyle.CssClass=“ms viewheadertr ms vhlt”;
_lastCreateDjobGrid.RowStyle.CssClass=“ms itmHoverEnabled ms itmhover”;
_LastCreateDjobGrid.AutoGenerateColumns=false;
_LastCreateDjobGrid.EmptyDataText=Constants.Messages.NoJobsFound;
控件。添加(_lastCreatedJobGrid);
LoadGridData();
}
捕获(例外情况除外)
{
LoggingService.LogError(LoggingCategory.Job,ex);
}
}
私有void\u lastCreatedJobsGrid\u RowDataBound(对象发送方,GridViewRowEventArgs e)
{
尝试
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
JobInfo JobInfo=(JobInfo)e.Row.DataItem;
如果(jobInfo.IsConfidential)
{
var newHyperLink=新超链接
{
文本=@“”,
NavigateUrl=jobInfo.xlink
};
e、 Row.Cells[2]。Controls.RemoveAt(0);
e、 行。单元格[2]。控件。添加(新建超链接);
}
}
}
捕获(例外情况除外)
{
LoggingService.LogError(LoggingCategory.Job,ex);
}
}
#区域私有方法
私有void LoadGridData()
{
尝试
{
字符串currentUrl=SPContext.Current.Site.Url;
var jobInfoList=新列表();
SPSecurity.RunWithElevatedPrivileges(委托
{
使用(var clientsitecolection=new SPSite(currentUrl))
{
弗雷奇(
spwebin
clientSiteCollection.AllWebs.Where(
c=>
c、 AllProperties[Constants.WebProperties.General.WebTemplate]!=null&&
c、 AllProperties[Constants.WebProperties.General.WebTemplate].ToString()==
常量.WebTemplates.JobWebPropertyName).OrderByDescending(d=>d.Created).Take(5)
)
{
SPList jobInfoListSp=web.Lists.TryGetList(Constants.Lists.JobInfoName);
如果(jobInfoListSp!=null)
{
如果(jobInfoListSp.Items.Count>0)
{
var值=
新SPFieldUrlValue(
jobInfoListSp.Items[0][Constants.FieldNames.Job.iPowerLink].ToString();
jobInfoList.Add(新的JobInfo
{
JobName=jobInfoListSp.Items[0][Constants.FieldName.Job.JobName].ToString(),
JobCode=jobInfoListSp.Items[0][Constants.FieldName.Job.JobCode].ToString(),
xlink=value.Url,
JobWebsite=web.Url,
IsConfigdential=HelperFunctions.ConvertToBoolean(jobInfoListSp.Items[0][Constants.FieldNames.Job.Confi
<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>");