我正在使用一个 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) 会正确显示。如果没有,则标签不会出现/更新。有问题的方法不会更新表单上的任何控件或项。