Dr. Rajesh Rolen
Dr. Rajesh Rolen

Reputation: 14285

Invalid postback or callback argument

I am facing this error when i attach specific datasource with dropdownlist. with all other tables/datasources its working fine. I am not doing any changes in dropdownlist using javascript/jquery (as its working fine with all other datasource except current)

error:

Invalid postback or callback argument.  Event validation is

enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

my function to get values from xml files:

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;


}

This is how i am binding it with my dropdownlist:

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

When i bind same dropdownlist with any other datasource (non-xml) its working fine .. but when i am doing it with this datasource its throwing that above error.

My xml is like:

<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>

its successfully retriving data and showing on dropdownlist but when i select any item from it (selected index changed) then it shows this message...

Thanks

Upvotes: 1

Views: 675

Answers (2)

Dr. Rajesh Rolen
Dr. Rajesh Rolen

Reputation: 14285

Finally i resolved the issue... while using LINQ, i just used Trim() and its done... :)

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()
                          };

so my final conclusion is there must me problem of blank space with value...

Upvotes: 1

rkw
rkw

Reputation: 7297

That error usually crops up when your input elements, including drop downlists, contains either of these characters '<' or '>'.

Have you tried encoding those values if they exist?

Upvotes: 1

Related Questions