I have a page with a repeater and a button. (quite simple)
My repeater have an event rptEtats_ItemCreated raised OnItemCreated
<asp:Repeater ID="rptEtats" runat="server" OnItemCreated="rptEtats_ItemCreated">
<ItemTemplate>
</ItemTemplate>
</asp:Repeater>
CodeBehind:
public void rptEtats_ItemCreated(object sender, RepeaterItemEventArgs e)
{
//Stuff
}
The button on the page raise a OnClick event
<asp:Button ID="btnValid" runat="server" Text="Valid" OnClick="btnValid_click" />
CodeBehind:
public void btnValid_click(Object sender, EventArgs e)
{
//Stuff
}
It’s work fine until I click on the button, I expect the btnValid_click method but the rptEtats_ItemCreated method is called first! I don’t understand why. Is the page load again before call the button method? Why the repeater is databinding again?
You have to cal
rptEtats.Databind();at Page_Init, that is before view state is loaded. In that case controls would be re-created properly and button onclik would be fired.