This has been driving me crazy for 2 days now - hope someone has seen this before.
I have this issue where the first click of a control within a repeater or grid view fails to fire the ItemCommand event, all subsequent clicks work. The controls are being loaded into a placeholder on Base.aspx like so
private void LoadUserControl()
{
string controlPath = LastLoadedControl;
if (!string.IsNullOrEmpty(controlPath))
{
ph.Controls.Clear();
UserControl uc = (UserControl)LoadControl(controlPath);
ph.Controls.Add(uc);
}
}
I'm wondering if this is a viewstate issue, and in which page events I should use DataBind(). I've experimented with databind in different page events, enabling viewstate on page and control without variation in result.
here's the GridView template , but I have also the same behaviour with a repeater control so I don't believe its the control which is this issue.
<ItemTemplate>
<asp:RadioButton ID="rbEnable" GroupName="MyGroup" runat="server" Text="Enabled" Checked="<%# ((EducateMe.BaseTypes.AbstractLink)Container.DataItem).IsActive == true %>" />
<asp:RadioButton ID="rbDisable" runat="server" GroupName="MyGroup" Text="Disabled" Checked="<%# ((EducateMe.BaseTypes.AbstractLink)Container.DataItem).IsActive != true %>" />
<asp:Button ID="btnEnable" runat="server" CommandArgument="<% # Container.DataItemIndex %>" CommandName="Enable" ToolTip="Enable" Text="Save" />
<asp:Button ID="btnDisable" runat="server" CommandArgument="<% # Container.DataItemIndex %>" Visible="false" CommandName="Disable" ToolTip="Disable" Text="Disable" />
</ItemTemplate>
Some further info which might be relevant:
What I've noticed is in the Page_Load event of the usercontrol is where I'm rebinding the control. This is probably the cause as the control state gets rewritten, but if I add a if(!IsPostback) to this area in the ascx, this code section doesnt fire at all like it does on an aspx page. That would be the correct section to rebind the control I think.