多视图未在 Ektron 页面构建器小部件中的回发上运行脚本
Multiviews Not Running Scripts on Postback Inside Ektron Pagebuilder Widget
我的 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, Server 2008 R2, SQL Server 2008.
当小部件在视图之间切换(即从视图切换到编辑)时,它使用 Ajax 回发(我相信在 UpdatePanel 中)执行此操作。 这意味着任何内联脚本或设置为运行"onload"的任何脚本都不会由于部分回发而执行。
因此,您需要专注于如何在 UpdatePanel 刷新后使 JavaScript 代码执行。 你可以尝试这样的事情:
function foo()
{
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}
function endRequestHandler(sender, args)
{
// Do your stuff
alert('Update Panel routine is now complete');
}
相关文章:
- Google 脚本:用于创建日历活动的脚本运行时不会出错,但不会执行任何操作
- Chrome没有加载最新版本的web工作程序脚本(运行缓存版本)
- 从 jquery.ready() 调用的 javascript 何时相对于 中的脚本运行
- 如何从其中的另一个jquery脚本运行.load()
- 这个对象构造函数阻止我的脚本运行
- 当作为脚本运行时.js Node中“this”的上下文是什么
- 如何使 Tampermonkey 添加的函数在脚本运行后在控制台中可用
- 当脚本运行时,它每秒将 4px 添加到我的容器的高度,只发生在 Firefox 中
- 我可以阻止我的 HTML 页面加载,直到我的 Facebook 登录状态脚本运行之后
- 从 PHP 脚本运行 Javascript 函数
- 我如何将脚本运行到从 jQuery 加载特定标签加载的另一个页面
- 在 PHP 脚本运行时添加加载图像
- 在IE中导致“脚本运行缓慢”警告
- Javascript - 脚本 1 停止,直到脚本 2 运行
- 脚本运行不正确的功能
- ajax脚本运行后指向页面的链接(javascript锚点?)
- 在脚本运行之前终止与浏览器的连接
- 脚本运行时,无法从FTP服务器自动下载文件
- 如何在外部JS脚本运行完成后运行函数
- 根据设备大小阻止脚本运行