Kohnarik
Kohnarik

Reputation: 377

Repeater Error when used twice

I have a Repeater, which contains several ImageButton elements. The first time I add a list of images to the Datasource of that Repeater, it works perfectly fine:

Repeater.DataSource = images;
Repeater.DataBind();

I have a TextChanged - event somewhere and inside that Event, I want to overwrite the DataSource with a new list of images.

When I do that, I receive a CallBack error. Commenting out the first DataBind makes the second one work perfectly. How can I resolve that problem?

Edit: The error message I receive is in german (here: http://i.imgur.com/M9wxexm.jpg), but roughly translated, it means: Invalid postback or callback argument. Event validation is enabled using <.pages enableEventValidation=“true”/.> ...

Upvotes: 2

Views: 183

Answers (1)

Sunil
Sunil

Reputation: 21406

Since you are getting a callback error, you should try disabling event validation for your aspx page. This needs to be done in page directive which will be at top of your aspx page.

<%@ Page EnableEventValidation="false"%>

Also keep the following facts in mind.

  1. For the first databind, I am assuming it's in the Page_Load event. If that is the case then make sure that it's only executed when page is not posting back since on page post back you have text changed logic to populate the repeater.

    protected void Page_Load( object sender, EventArgs e) 
    {
      if(!Page.IsPostBack)
       {
        Repeater.DataSource = images;
        Repeater.DataBind();
       }
    }
    
  2. Then in your text changed event databind the same repeater and make sure you call the DataBind method after setting it's data source. So, include both the lines below in your text changed event handler. Of course, the images variable needs to be replaced by the appropriate variable in text-changed event.

        Repeater.DataSource = images;
        Repeater.DataBind();
    

Upvotes: 1

Related Questions