【发布时间】:2013-03-07 05:12:50
【问题描述】:
我正在使用一个 Visual WebPart (c#),它由一个包含 Web 表单内容的 UpdatePanel 组成。在此表单上,在 UpdatePanel 中,我有一个 asp.net 标签,它的 text 属性设置基于提交的结果。它在执行后设置为可见,并且它的前景色也会根据错误或成功进行更改。这完美地工作(文本更新/变得可见),直到我决定在按下提交按钮时调用特定方法。调用此方法时,文本属性不更新,标签不显示。
我已多次调试此过程,每次我逐步完成该过程并看到正确的消息,看到它被应用于标签的文本属性,并且完成但页面没有更新。我可以通过注释掉方法调用来重现工作功能。没有错误被抛出。程序在调试时似乎可以正常执行。
提交按钮代码摘录:
try
{
CreateElementOnDestinationWebs(this.ddlSupportedElements.SelectedValue.ToString(), elementName, ref messages);
msg = String.Format("<br />We have successfully created your {0}. Please review the following outcomes: <br /><ul>", this.ddlSupportedElements.SelectedItem.Text);
foreach (string m in messages)
{
msg += String.Format("<li>{0}</li>", m);
}
msg += "</ul>";
labelMessages.Text = msg;
labelMessages.Visible = true;
labelMessages.ForeColor = System.Drawing.Color.ForestGreen;
}
catch (Exception ex)
{
msg = String.Format("<br />An unexpected error occurred while creating the item: {0}", ex.ToString());
labelMessages.Text = msg;
labelMessages.Visible = true;
labelMessages.ForeColor = System.Drawing.Color.Maroon;
}
CreateElementOnDestinationWebs 来源:
try
{
Guid listId = web.Lists.Add(name, "Student work can be submitted here.", SPListTemplateType.DocumentLibrary);
web.Update();
SPList newList = web.Lists[listId];
newList.OnQuickLaunch = this.checkDropBoxShowOnQuickLaunch.Checked;
newList.EnableModeration = true;
newList.Update();
GrantStudentGroupsContributeRights(web, ref newList, ref msgs);
try
{
DetectAddColumnsToDropbox(web, ref newList, ref msgs);
}
catch (Exception)
{
msgs.Add("There was an unexpected error while attempting to add the site columns to the library.");
}
msgs.Add(String.Format("Your item: {0}, has been successfully created on site: <a href='{1}' target='_blank'>{2}</a>", name, web.Url, web.Title));
}
catch (Exception)
{
msgs.Add(String.Format("An error occurred while creating the document library for student work on site: <a href='{0}' target='_blank'>{1}</a>", web.Url, web.Title));
}
如果包含“DetectAddColumnsToDropbox”的 try 块被注释掉,则标签 (labelMessages) 会正确显示。如果没有,则标签不会出现/更新。有问题的方法不会更新表单上的任何控件或项。
【问题讨论】:
-
您能否展示您在问题中引用的代码?当您进行 PostBack 时,这个特殊问题也会发生吗?请记住,UpdatePanel 执行
Partial PostBacks -
按钮是否在更新面板中?对我来说,回发按钮似乎不会触发更新事件。您甚至可以显式调用面板的更新方法。你有嵌套的更新面板吗?
-
是的。该按钮位于更新面板中。它正在完成工作。所有操作成功结束,但标签不显示文本。 UpdateProgress 代码每次都会触发。
标签: c# asp.net sharepoint-2010 web-parts