我的 Ektron 页面构建器小部件有一个奇怪的问题。
无论出于何种原因,当我从切换小部件视图的小部件内的任何按钮回发到服务器时,这些视图中的脚本都不会执行。
控制小部件所处“模式”的多视图似乎是表面上的常规多视图,所以我不确定它为什么会这样。我已经通过向页面添加第二个多视图来测试这一点,它只交换视图和警报,当放置在小部件外部的模板上时,它按预期工作,但在小部件内部时无法执行其脚本。此外,当在小部件内单击任何按钮时,ektron 会打开一个加载图像,当服务器回发时该图像会消失,无论单击哪个多视图。这让我相信 Ektron 正在积极地做一些事情来抑制这些小部件脚本的执行,尽管我什至不确定它会怎么做,因为脚本一旦渲染就正确地出现在视图中。
小部件代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestWidget.ascx.cs" Inherits="widgets_TestWidget" %>
<asp:MultiView ID="ViewSet" runat="server" ActiveViewIndex="0">
<asp:View ID="View" runat="server">
<script>alert('this runs');</script>
<asp:Label ID="OutputLabel" runat="server"></asp:Label>
</asp:View>
<asp:View ID="Edit" runat="server">
<div id="<%=ClientID%>_edit">
<script>alert('but for some reason, this does not run');</script>
<asp:TextBox ID="HelloTextBox" runat="server" Style="width: 95%"> </asp:TextBox>
<asp:Button ID="CancelButton" runat="server" Text="Cancel" OnClick="CancelButton_Click" />
<asp:Button ID="SaveButton" runat="server" Text="Save" OnClick="SaveButton_Click" />
</div>
</asp:View>
</asp:MultiView>
<!--code below works properly outside of the widget and fails inside of it -->
<asp:MultiView ID="uxmulti" runat="server" ActiveViewIndex="0">
<asp:View ID="view1" runat="server">
<script>alert('this runs');</script>
<asp:Button ID="ux_b1" runat="server" OnClick="ux_b1_Click" Text="to edit" />
</asp:View>
<asp:View ID="edit1" runat="server">
<script>alert('as does this, but not inside the widget');</script>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="to view" />
</asp:View>
</asp:MultiView>
小部件代码隐藏:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Ektron.Cms.Widget;
using Ektron.Cms;
using Ektron.Cms.API;
using Ektron.Cms.Common;
using Ektron.Cms.PageBuilder;
using System.Configuration;
public partial class widgets_TestWidget : System.Web.UI.UserControl, IWidget
{
#region properties
private string _HelloString;
[WidgetDataMember("Hello World")]
public string HelloString { get { return _HelloString; } set { _HelloString = value; } }
#endregion
IWidgetHost _host;
protected ContentAPI m_refContentApi = new ContentAPI();
protected EkMessageHelper m_refMsg;
protected void Page_Init(object sender, EventArgs e)
{
string sitepath = new CommonApi().SitePath;
JS.RegisterJSInclude(this, JS.ManagedScript.EktronJS);
JS.RegisterJSInclude(this, JS.ManagedScript.EktronModalJS);
Css.RegisterCss(this, Css.ManagedStyleSheet.EktronModalCss);
_host = Ektron.Cms.Widget.WidgetHost.GetHost(this);
m_refMsg = m_refContentApi.EkMsgRef;
_host.Title = m_refMsg.GetMessage("lbl hello world widget");
_host.Edit += new EditDelegate(EditEvent);
_host.Maximize += new MaximizeDelegate(delegate() { Visible = true; });
_host.Minimize += new MinimizeDelegate(delegate() { Visible = false; });
_host.Create += new CreateDelegate(delegate() { EditEvent(""); });
CancelButton.Text = m_refMsg.GetMessage("btn cancel");
SaveButton.Text = m_refMsg.GetMessage("btn save");
PreRender += new EventHandler(delegate(object PreRenderSender, EventArgs Evt) { SetOutput(); });
string myPath = string.Empty;
if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["ek_helpDomainPrefix"]))
{
string helpDomain = ConfigurationManager.AppSettings["ek_helpDomainPrefix"];
if ((helpDomain.IndexOf("[ek_cmsversion]") > 1))
{
myPath = helpDomain.Replace("[ek_cmsversion]", new CommonApi().RequestInformationRef.Version);
}
else
{
myPath = ConfigurationManager.AppSettings["ek_helpDomainPrefix"];
}
}
else
{
myPath = sitepath + "Workarea/help";
}
_host.HelpFile = myPath + "EktronReferenceWeb.html#Widgets/Creating_the_Hello_World_Widget.htm";
ViewSet.SetActiveView(View);
}
protected void SetOutput()
{
OutputLabel.Text = HelloString;
}
void EditEvent(string settings)
{
HelloTextBox.Text = HelloString;
ViewSet.SetActiveView(Edit);
}
protected void SaveButton_Click(object sender, EventArgs e)
{
HelloString = HelloTextBox.Text;
_host.SaveWidgetDataMembers();
ViewSet.SetActiveView(View);
}
protected void CancelButton_Click(object sender, EventArgs e)
{
ViewSet.SetActiveView(View);
}
protected void ux_b1_Click(object sender, EventArgs e)
{
uxmulti.SetActiveView(edit1);
}
protected void Button1_Click(object sender, EventArgs e)
{
uxmulti.SetActiveView(view1);
}
}
这可以使用脏 eval 语句来解决,但这远非理想。关于为什么会以这种方式表现或如何解决它的任何想法?
Ektron 8.6.1、服务器 2008 R2、SQL Server 2008。