Reputation: 2291
I've a webapplication with UserControls. When I click on a menu-item or a select-button in a grid, than I see that didn't react the first time. When I clicked for the second time then an event behind the button will fire.
What do I wrong? I've given the components a unique ID and the events are in the cs-files.
I hope someone can help me.
thanks.
The problems is in the two following examples:
<asp:Menu ID="TabMenu" Width="100%" Height="25px" runat="server"
Orientation="Horizontal" CssClass="TabPages"
StaticEnableDefaultPopOutImage="False"
AutoPostBack="true"
OnMenuItemClick="DoMenuItemClick" >
<Items>
<asp:MenuItem Text="Domains" Value="0"></asp:MenuItem>
In this case for the first time, when you clicked on a menu-item, it looks like the page only is reloaded. And when clicks for the second time, the event really fires. In this example when you clicks on a menu-item, the right View is shown.
<asp:GridView ID="gvwSelection" runat="server"
AllowPaging="True"
SelectedIndex="1"
AutoGenerateSelectButton="True"
OnSelectedIndexChanged="gvwSelectie_SelectedIndexChanged"
OnSelectedIndexChanging="gvwSelectie_SelectedIndexChanging" >
<PagerStyle ForeColor="#00257e" HorizontalAlign="Right"
BackColor="#FFFFFF"></PagerStyle>
</asp:GridView>
Example 2: The first time you click on a selection button, then the row you touched is not selected. And after the first time everything works correct.
The ID's have a fixed name. The AutoPostBack is set to True. There is an event linked. The grids has DataBinded. There is site.master a default.aspx and the UserControls are placed in a Placeholder.
I hope someone can help me.
Upvotes: 0
Views: 3718
Reputation: 2291
I've found and solved the problem.
I have a dynamic UserControl FAddress and everytime he is wearing another control. So I added the following row in the method: FAddress.ID = "UserControl1";
The problem was, that the control was loading everytime. By giving this dynamic control a fixed ID, this item has solved.
private void LoadPage(string APageName)
{
FAddress = null;
PlaceholderAddressTemplate.Controls.Clear();
if (!string.IsNullOrEmpty(APageName))
{
FAddress = (UserControl)LoadControl(string.Format("~/UserControls/{0}.ascx",
APageName));
if (FAddress != null)
{
FAddress.ID = "UserControl1";
PlaceholderAddressTemplate.Controls.Add(FAddress);
ShowOrHideComponents();
FAddress.Focus();
}
else
ShowOrHideComponents();
}
else
ShowOrHideComponents();
}
Upvotes: 1
Reputation: 1157
Ensure that the autopostback property is set to true behind your button, that may solve your problem.
Upvotes: 0