Click here to Skip to main content
14,773,274 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

I have an asp:repeater which includes an asp:dropdownlist in its template as well as an update panel. The asp:dropdownlist is outside of the update panel.

I am using the repeater.ItemDataBound event to populate the repeater items.

The only postback trigger I have for the update panel is the dropdownlist.

I have to check the e.item.FindControl("dropdownlist").UniqueID against the Request.Form["__EVENTTARGET"] to make sure I'm updating the correct update panel, and I use the value of Request.Form[e.item.FindControl("dropdownlist").UniqueID] to update the items within the updatepanel. I then have to call updatepanel.Update().

This works fine the first time, but then I get the event validation error after that.

Is there a way I can avoid turning off event validation?

do I have to wrap all of my controls in the update panel?

Thanks

PS
Here is some code (ugly because still incomplete)

//ItemDataBoundEventHandler
void RepeaterItemDataBound(object sender, RepeaterItemEventArgs e)
{
    CalenderDate calDate = e.Item.FindControl("calDate") as CalenderDate;
    Label lblNumber = e.Item.FindControl("lblNumber") as Label;

    Label lblda = e.Item.FindControl("lblda") as Label;
    Label lbldd = e.Item.FindControl("lbldd") as Label;
    Label lbldt = e.Item.FindControl("lbldt") as Label;
    Label lblaa = e.Item.FindControl("lblaa") as Label;
    Label lblad = e.Item.FindControl("lblad") as Label;
    Label lblat = e.Item.FindControl("lblat") as Label;

    DropDownList ddlp = e.Item.FindControl("ddlp") as DropDownList;

    ReadOnlyFormControl vlblForname = e.Item.FindControl("vlblForname") as ReadOnlyFormControl;
    ReadOnlyFormControl vlblSurname = e.Item.FindControl("vlblSurname") as ReadOnlyFormControl;

    UpdatePanel uppDetails = e.Item.FindControl("uppDetails") as UpdatePanel;


    Model.FInstance fInstance = e.Item.DataItem as Model.FInstance;

    if (!IsPostBack)
    {

        ddlp.Bind(GetPList(fInstance.InternalId), "InternalId", "FullName");

        calDate.Date = fInstance.sd;

        lblNumber.Text = string.Format("{0}", fInstance.Number);

        lblda.Text = string.Format("{0}", fInstance.daCode);
        lbldd.Text = string.Format("{0}", (fInstance.sd).ToString("dd/MM/yyyy"));
        lbldt.Text = string.Format("{0}", (fInstance.sd).ToString("HH:mm"));

        lblaa.Text = string.Format("{0}", fInstance.daCode);
        lblad.Text = string.Format("{0}", (fInstance.sa).ToString("dd/MM/yyyy"));
        lblat.Text = string.Format("{0}", (fInstance.sa).ToString("HH:mm"));

        if (ddlp.Items.Count > 0 && ddlp.SelectedIndex > -1)
        {
            Model.P p= GetP(ddlp.SelectedValue);

            vlblForname.Text = p.Forename;
            vlblSurname.Text = p.Surname;
            upPDetails.Update();
        }

    }
    else
    {
        var requestTarget = Request.Form["__EVENTTARGET"];

        if (requestTarget.Equals(ddlp.UniqueID))
        {
            string pId = Request.Form[ddlp.UniqueID];

            Model.P p = GetP(pId);

            vlblForname.Text = p.Forename;
            vlblSurname.Text = p.Surname;
            uppDetails.Update();
        }
    }
}


<asp:Repeater runat="server" ID="rptFRepeater">
    <ItemTemplate>
        <div class="panel panel-default">
            <div class="panel panel-body">
                <div class="panel panel-heading">
                    <h4>Ident: <asp:Label CssClass="strong" runat="server" ID="lblNumber" /></h4>
                </div>
                <div class="col-sm-1">
                    <util:Calendar  runat="server" ID="calDate"/>
                </div>
                <div class="col-sm-5">
                                        
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="styled-header">
                                 D
                            </div>
                            <table>
                                <tr>
                                    <td style="text-align: right">
                                        A:
                                    </td>
                                    <td>
                                        <asp:Label runat="server" ID="lblda" />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: right">
                                        Date:
                                    </td>
                                    <td>
                                        <asp:Label runat="server" ID="lbldd" />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: right">
                                        Time:
                                    </td>
                                    <td>
                                        <asp:Label runat="server" ID="lbldt" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-sm-6">
                            <div class="styled-header">
                                 A
                            </div>
                            <table>
                                <tr>
                                    <td style="text-align: right">
                                        A:
                                    </td>
                                    <td>
                                        <asp:Label runat="server" ID="lblaa" />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: right">
                                        D:
                                    </td>
                                    <td>
                                        <asp:Label runat="server" ID="lblad" />
                                    </td>
                                </tr>
                                <tr>
                                    <td style="text-align: right">
                                        T:
                                    </td>
                                    <td>
                                        <asp:Label runat="server" ID="lblat" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>     
                </div>
                <div class="col-sm-6">
                    <div class="col-sm-12">
                        <div class="styled-header">
                             P
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <asp:DropDownList runat="server" ID="ddlp" CssClass="list-box-full-width" AutoPostBack="true"/>
                    </div>
                    <div class="col-sm-6">
                        <asp:UpdatePanel runat="server" ID="upDetails" ChildrenAsTriggers="false" UpdateMode="Conditional">
                            <ContentTemplate>
                                <div class="form-horizontal">
                                    <vlbl:ReadOnlyFormControl  runat="server" ID="vlblForname" Label="Forename"/>
                                    <vlbl:ReadOnlyFormControl  runat="server" ID="vlblSurname" Label="Surname"/>
                                </div>
                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="ddlp" EventName="SelectedIndexChanged"/>
                            </Triggers>
                        </asp:UpdatePanel>
                    </div>
                </div>
            </div>
        </div>
    </ItemTemplate>
</asp:Repeater>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900