Sharepoint 控件在回发时的不同行为

发布于 2024-12-10 16:29:55 字数 1573 浏览 2 评论 0原文

遗憾的是,一些 Sharepoint 控件在回发时表现不同: 我从以下开始:

<SharePointWebControls:NoteField id="3" FieldName="MultiText" runat="server" />
<PublishingWebControls:RichLinkField id="4" FieldName="Link" runat="server" />

这些控件呈现空白字段。这会导致回发时出现不需要的空白。 经过一番研究,我找到了一个解决方案,例如 建议 此处

<PublishingWebControls:EditModePanel runat=server id="EditModePanelView" PageDisplayMode="Display" SuppressTag="true">
   <SharePointWebControls:FieldValue id="3" FieldName="MultiText" runat="server"/>
   <SharePointWebControls:FieldValue id="4" FieldName="Link" runat="server" />
</PublishingWebControls:EditModePanel>

<PublishingWebControls:EditModePanel runat="server" id="EditModePanelEdit">
   <SharePointWebControls:NoteField id="7" FieldName="MultiText" runat="server" />
   <PublishingWebControls:RichLinkField id="8" FieldName="Link" runat="server" />
</PublishingWebControls:EditModePanel>

...不再有空白字段:

现在又出现了新的问题: 当呈现为 SharePointWebControls:FieldValue 时,在 NoteField 的编辑模式下输入的任何换行符(呈现为 br-Tags)都会丢失。有什么方法可以像显示模式一样渲染 NoteField 的 html 吗?这样分行就不会丢失并且没有额外的非分行空格?

Some Sharepoint controls sadly behave different on postback:
I started with:

<SharePointWebControls:NoteField id="3" FieldName="MultiText" runat="server" />
<PublishingWebControls:RichLinkField id="4" FieldName="Link" runat="server" />

These controls render   for blank fields. That lead to unwanted whitespace on postback.
After some research I found a solution like
suggested here :

<PublishingWebControls:EditModePanel runat=server id="EditModePanelView" PageDisplayMode="Display" SuppressTag="true">
   <SharePointWebControls:FieldValue id="3" FieldName="MultiText" runat="server"/>
   <SharePointWebControls:FieldValue id="4" FieldName="Link" runat="server" />
</PublishingWebControls:EditModePanel>

<PublishingWebControls:EditModePanel runat="server" id="EditModePanelEdit">
   <SharePointWebControls:NoteField id="7" FieldName="MultiText" runat="server" />
   <PublishingWebControls:RichLinkField id="8" FieldName="Link" runat="server" />
</PublishingWebControls:EditModePanel>

...no   in blank fields anymore:

Now a new problem occured:
Any line breaks (rendered as br-Tags) that are entered in edit mode for a NoteField are lost, when rendered as SharePointWebControls:FieldValue. Is there any way to render the html of the NoteField as is in display mode? So that the breaks don't get lost and there are no additional non-breaking spaces?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感悟人生的甜 2024-12-17 16:29:55

我最终按照建议覆盖了 Sharepoint 控件 此处

我必须覆盖NoteField#RenderFieldForDisplay 这样,这样 NoteField在回发和 GET 上的行为相同:

protected override void RenderFieldForDisplay(HtmlTextWriter output)
{
  TextWriter writer = new StringWriter();
  base.RenderFieldForDisplay(new HtmlTextWriter(writer));
  string x=  writer.ToString();
  string y= " ";
  string z= "<br/>";
  x= x.Equals(y) ? x.Replace(y, string.Empty) : x.Replace(" ", y).Replace("\r\n", z).Replace("\n", z).Replace("\r", z);
  output.Write(x);
}

这可以工作,但很糟糕。我仍然不明白为什么共享点控件在回发时表现不同,并将例如 br-Tags 替换为换行符......

I ended up with overwriting the Sharepoint Controls like suggested here:

I had to overwrite NoteField#RenderFieldForDisplay like this, so that NoteField behaves the same on postback and on GET:

protected override void RenderFieldForDisplay(HtmlTextWriter output)
{
  TextWriter writer = new StringWriter();
  base.RenderFieldForDisplay(new HtmlTextWriter(writer));
  string x=  writer.ToString();
  string y= " ";
  string z= "<br/>";
  x= x.Equals(y) ? x.Replace(y, string.Empty) : x.Replace(" ", y).Replace("\r\n", z).Replace("\n", z).Replace("\r", z);
  output.Write(x);
}

This works but it sucks. I still don't get it why sharepoint controls behave different on postback and replace e.g. br-Tags with line breaks...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文