1

当我使用下拉列表附加特定数据源时,我遇到了这个错误。与所有其他表/数据源一起工作正常。我没有使用 javascript/jquery 对下拉列表进行任何更改(因为它可以与除当前数据源之外的所有其他数据源一起正常工作)

错误:

Invalid postback or callback argument.  Event validation is

在配置中使用或在页面中启用 <%@ Page EnableEventValidation="true" %>。出于安全目的,此功能验证回发或回调事件的参数是否源自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用 ClientScriptManager.RegisterForEventValidation 方法注册回发或回调数据以进行验证。

我从 xml 文件中获取值的函数:

public List<ProductReviewmaster> ConvertRssXDocToReviews(XDocument xdoc)
{
    List<ProductReviewmaster> nl = new List<ProductReviewmaster>();

    if (xdoc != null)
    {
        var res = from rs in xdoc.Descendants("item")
                  select new ProductReviewmaster()
                  {
                      Title = rs.Element("title").Value,
                      ShortHeadLine = rs.Element("shortheadline").Value,
                      Link = rs.Element("link").Value,
                      Reviewid = rs.Element("guid").Value ,
                      //Pubdate = Convert.ToDateTime( rs.Element("pubdate").Value),
                      Image = rs.Element("storyimage").Value,
                      Dateline = rs.Element("dateline").Value,
                      Excerpt = rs.Element("excerpt").Value,
                      Tags = rs.Element("tags").Value,
                      ProductId = rs.Attribute("productid").Value.ToInt64()
                  };
        foreach (var item in res)
        {
            nl.Add(item);

        }
    }
    return nl;


}

这就是我将它与我的下拉列表绑定的方式:

   ddlReview.DataSource =  prmf.GetReviewByCategoryKey(categoryid);
                ddlReview.DataValueField = "Reviewid";
                ddlReview.DataTextField = "Title";
                ddlReview.DataBind();
                ddlReview.Items.Insert(0, new ListItem("---Select---"));

当我将相同的下拉列表与任何其他数据源(非 xml)绑定时,它工作正常..但是当我使用这个数据源进行操作时,它会抛出上述错误。

我的xml就像:

<rss version="2.0">
  <channel>
    <title>

        </title>
    <link>

        </link>
    <language>en</language>
    <lastBuildDate>
            August  3, 2011  3:57 PM
        </lastBuildDate>
    <image>
      <url></url>
      <link>
            </link>
    </image>
    <items>
      <item productid="">
        <title><![CDATA[This is new test review]]></title>
        <shortheadline><![CDATA[]]></shortheadline>
        <link>

                    </link>
        <permaLink>
          <web>

                        </web>
        </permaLink>
        <guid isPermaLink="false">
                        29527
                    </guid>
        <pubDate>
                        August  2, 2011  1:56 PM
                    </pubDate>
        <MobileText></MobileText>
        <storyimage><![CDATA[ges/apple-appstore.jpg]]></storyimage>
        <categories><![CDATA[mobile]]></categories>
        <dateline><![CDATA[]]></dateline>
        <excerpt><![CDATA[isational structure for its operations in India and South Asia with effetransformational business...]]></excerpt>
        <tags><![CDATA[mobile, phone]]></tags>
        <contenttype><![CDATA[Review]]></contenttype>
      </item>
    </items>
    <description></description>
  </channel>
</rss>

它成功检索数据并显示在下拉列表中,但是当我从中选择任何项目(所选索引已更改)时,它会显示此消息...

谢谢

4

2 回答 2

1

当您的输入元素(包括下拉列表)包含这些字符“<”或“>”时,通常会出现该错误。

如果它们存在,您是否尝试过对这些值进行编码?

于 2011-08-04T06:13:51.773 回答
1

最后我解决了这个问题......在使用 LINQ 时,我只是使用了 Trim() 并完成了...... :)

var res = from rs in xdoc.Descendants("item")
                          select new ProductReviewmaster()
                          {
                              Title = rs.Element("title").Value.Trim(),
                              ShortHeadLine = rs.Element("shortheadline").Value.Trim(),
                              Link = rs.Element("link").Value.Trim(),
                              Reviewid = rs.Element("guid").Value.Trim() ,
                              //Pubdate = Convert.ToDateTime( rs.Element("pubdate").Value),
                              Image = rs.Element("storyimage").Value.Trim(),
                              Dateline = rs.Element("dateline").Value.Trim(),
                              Excerpt = rs.Element("excerpt").Value.Trim(),
                              Tags = rs.Element("tags").Value.Trim(),
                              ProductId = rs.Attribute("productid").Value.ToInt64()
                          };

所以我的最终结论是我必须有有价值的空白空间问题......

于 2011-08-04T06:20:24.510 回答