【问题标题】:DevExpress controls in Sitecore not posting backSitecore 中的 DevExpress 控件未回发
【发布时间】:2015-07-22 11:41:12
【问题描述】:

我在使 DevExpress 控件在 Sitecore (7.5) 中工作时遇到了一些问题。我已经通过在 Sitecore 解决方案之外的 aspx 页面中使用相同的代码(但在同一个 IIS 站点中)验证了使用 Sitecore 中的控件存在问题。

问题是在 DevExpress Combobox 控件的回发时,我没有得到任何选定的值。我尝试了以下方法;

添加到 web.config:

<rendering>
    <typesThatShouldNotBeExpanded>
        <type>DevExpress.Web</type>
    </typesThatShouldNotBeExpanded>
</rendering>

还尝试将 DXR.axd 添加到 web.config 中的 Sitecore“IgnoreUrlPrefixes”设置。 我还尝试在 DevEx 控件上设置 EnableCallbackMode="false"。

这是我使用的测试代码,它在普通的 aspx 页面中工作,但不是子布局的一部分。

ASPX:

<%@ Register Assembly="DevExpress.Web.v14.2, Version=14.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>
<%@ Register TagPrefix="sc" Namespace="Sitecore.Web.UI.WebControls" Assembly="Sitecore.Kernel" %>

<dx:ASPxPopupControl ID="ASPxPopupControl1" runat="server" ShowOnPageLoad="true">
    <ContentCollection>
        <dx:PopupControlContentControl>
            <dx:ASPxFormLayout ID="ASPxFormLayout1" runat="server">
                <Items>
                    <dx:LayoutGroup Caption="Testing">
                        <Items>
                            <dx:LayoutItem>
                                <LayoutItemNestedControlCollection>
                                    <dx:LayoutItemNestedControlContainer>
                                        <dx:ASPxLabel runat="server" Text="ASPxLabel" AssociatedControlID="ComboBox"></dx:ASPxLabel>
                                        <dx:ASPxComboBox ID="ASPxComboBoxLoja" runat="server" CssFilePath="~/App_Themes/DevEx/{0}/styles.css"
                                            CssPostfix="DevEx" ValueField="codigo" SpriteCssFilePath="~/App_Themes/DevEx/{0}/sprite.css"
                                            ValueType="System.Guid" ClientIDMode="AutoID" Spacing="0" EnableCallbackMode="false">
                                            <LoadingPanelImage Url="~/App_Themes/DevEx/Editors/Loading.gif">
                                            </LoadingPanelImage>
                                            <Columns>
                                                <dx:ListBoxColumn Caption="Loja" FieldName="nome" />
                                            </Columns>
                                            <LoadingPanelStyle ImageSpacing="5px">
                                            </LoadingPanelStyle>
                                        </dx:ASPxComboBox>
                                    </dx:LayoutItemNestedControlContainer>
                                </LayoutItemNestedControlCollection>
                            </dx:LayoutItem>
                        </Items>
                    </dx:LayoutGroup>
                    <dx:LayoutItem>
                        <LayoutItemNestedControlCollection>
                            <dx:LayoutItemNestedControlContainer>
                                <dx:ASPxButton runat="server" Text="ASPxButton" OnClick="Button_Click"></dx:ASPxButton>
                            </dx:LayoutItemNestedControlContainer>
                        </LayoutItemNestedControlCollection>
                    </dx:LayoutItem>
                </Items>
            </dx:ASPxFormLayout>
            <asp:Literal Text="" runat="server" ID="Output" />
        </dx:PopupControlContentControl>
    </ContentCollection>
</dx:ASPxPopupControl>

CS:

protected void Page_Load(object sender, EventArgs e)
        {
            ASPxComboBoxLoja.DataSource = CreateRightListDataSource();
            ASPxComboBoxLoja.DataBind();
        }

        private IEnumerable CreateRightListDataSource()
        {
            for (int i = 0; i < 100; i++)
            {
                yield return new { codigo = Guid.NewGuid(), nome = "nome " + i };
            }

        }

        protected void Button_Click(object sender, EventArgs e)
        {
            string retVal = ASPxComboBoxLoja.Value.ToString();
            Output.Text = retVal;
        }

在尝试检索值的按钮单击时发生错误。它为空(与所选项目一样)。屏幕上/Sitecore 日志中的错误:

异常:System.NullReferenceException 消息:对象引用未设置为对象的实例。

有让 DevExpress 控件在 Sitecore 中工作的经验吗?我确定我在做一些愚蠢的事情。

非常感谢。

【问题讨论】:

  • 您在 Sitecore 日志中看到任何错误吗?点击按钮时,浏览器控制台有没有报错?
  • 嗨@JayS,除了我在屏幕上看到的内容外,日志中没有任何内容(对象引用未设置为对象错误的实例)。我将更新上面的问题以反映这一点。谢谢。
  • devexpress 控件是否发出 JavaScript 并调用 http 模块?如果是这样您是否检查过您的控制台/提琴手以查看页面上正在进行的任何底层请求?
  • 嗨@goldengrahams,运行提琴手时没有错误。在 Sitecore 之外的页面上,我得到了表单数据,即“ASPxPopupControl1$ASPxFormLayout1$ASPxComboBoxLoja$DDD$L = e330d2cc-92ce-4af0-b8bd-38e1ab5c2488” 当通过 Sitecore 页面执行相同操作时,我仍然在回发时获得数据: "dbcontent_0$ASPxPopupControl1$ASPxFormLayout1$ASPxComboBoxLoja$DDD$L = dd78709d-1777-47fe-9225-8b3327e117af" 但是此时我确实得到了 obj。参考。错误。
  • 仅供参考,看起来 Sitecore 存在问题并使用了一些 .net 控件。如果您可以访问 SDN,可以在此处找到该文章:sdn.sitecore.net/scrapbook/…。我试过摆弄 web.config 中的 设置,但还没有运气。

标签: devexpress sitecore


【解决方案1】:

不完全确定,但这感觉像是回发的 .NET 事件循环问题。您在每次页面加载时重新绑定数据源,甚至回发。这通常会混淆视图状态。您是否尝试过使用 if(!IsPostBack) 包装数据绑定?

编辑:我还刚刚注意到,您每次呈现页面时都会生成一个新的 GUID。我不确定 Codigo 是什么,但您的第一次加载将具有与回发不同的 GUID。

【讨论】:

  • 您好 @jay 不幸的是,使用 devexpress 控件,您必须在每次往返服务器时将数据绑定到控件。我之前遇到过这个问题(参考:devexpress.com/Support/Center/Question/Details/KA18649)。我还生成了一个新的 GUID,只是为了创建一些测试数据。谢谢。
【解决方案2】:

感谢您的帮助。我设法通过更改配置中的 AutomaticDataBind 设置解决了这个问题。即 SC 包含文件:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <settings>
      <setting name="AutomaticDataBind">
        <patch:attribute name="value">true</patch:attribute>
      </setting>
    </settings>
  </sitecore>
</configuration>

更改&lt;typesThatShouldNotBeExpanded&gt; 似乎是正确的做法;然而它似乎没有任何效果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多