public partial class SpaceSettings : Spring.Web.UI.UserControl {
protected void SpaceSettingsButton_Click(object sender, EventArgs e) {
System.Diagnostics.Debug.WriteLine("SpaceSettings--------------");
}
}
UserSettings.ascx.cs:
public partial class SpaceSettings : Spring.Web.UI.UserControl {
protected void SpaceSettingsButton_Click(object sender, EventArgs e) {
System.Diagnostics.Debug.WriteLine("UserSettings--------------");
}
}
Now everything is fine, excpet the EventListeners correspond to the User button of UserSettings and Space button of SpaceSettings, are fireing on seond time and so on clicking.
I found the soultion. The problem is the ID of UserControlbeing added. I have modified two methods AddUserSettings and
AddSpaceSettings in the following way:
TapasBose_Ed...
0 Points
2 Posts
Dynamically Swapped UserControl: EventListeners of Buttons of UserControls are not firing
Apr 15, 2012 01:42 PM|LINK
I have two links, User Settings, Space Settings and two UserControls, UserSettings and SpaceSettings
What I want to do:
So I wrote the
SiteSettings.aspx:
<asp:UpdatePanel runat="server"> <ContentTemplate> <asp:Panel ID="Panel1" runat="server"> <asp:LinkButton ID="UserLink" runat="server" OnClientClick="$('#MainContent_JYM').val('User');" OnCommand="SettingsLink_OnCommand" CommandName="User" Text="User Settings" /> </asp:Panel> <asp:Panel ID="Panel2" runat="server"> <asp:LinkButton ID="SpaceLink" runat="server" OnClientClick="$('#MainContent_JYM').val('Space');" OnCommand="SettingsLink_OnCommand" CommandName="Space" Text="Space Settings" /> </asp:Panel> <asp:Panel ID="PlaceHolderPanel" runat="server" Style="min-height: 500px"> <asp:PlaceHolder runat="server" ID="SettingsPlaceholder" /> </asp:Panel> <asp:HiddenField runat="server" ID="JYM" /> </ContentTemplate> </asp:UpdatePanel>UserSettings.ascx:
<asp:Panel runat="server"> <asp:Button runat="server" ID="User" Text="User" onclick="UserSettingsButton_Click" /> </asp:Panel>SpaceSettings.ascx:
<asp:Panel runat="server"> <asp:Button runat="server" ID="Space" Text="Space" onclick="SpaceSettingsButton_Click" /> </asp:Panel>SiteSettings.ascx.cs:
public partial class SiteSettings : Page { protected void Page_Load(object sender, EventArgs e) { string key = JYM.Value; if (key == null || key.Trim().Length == 0) { AddUserSettings(); } else { if (key.Equals("User")) { AddUserSettings(); } else { AddSpaceSettings(); } } } protected void SettingsLink_OnCommand(object sender, CommandEventArgs commandEventArgs) { switch (commandEventArgs.CommandName) { case "User": AddUserSettings(); break; case "Space": AddSpaceSettings(); break; } } private void AddUserSettings() { AddSettings(LoadControl("~/UserControls/UserSettings.ascx") as UserSettings); } private void AddSpaceSettings() { AddSettings(LoadControl("~/UserControls/SpaceSettings.ascx") as SpaceSettings); } private void AddSettings(UserControl control) { SettingsPlaceholder.Controls.Clear(); SettingsPlaceholder.Controls.Add(control); } }SpaceSettings.ascx.cs:
public partial class SpaceSettings : Spring.Web.UI.UserControl { protected void SpaceSettingsButton_Click(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("SpaceSettings--------------"); } }UserSettings.ascx.cs:
public partial class SpaceSettings : Spring.Web.UI.UserControl { protected void SpaceSettingsButton_Click(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine("UserSettings--------------"); } }Now everything is fine, excpet the EventListeners correspond to the User button of UserSettings and Space button of SpaceSettings, are fireing on seond time and so on clicking.
How can I solve this problem?
Thanks.
TapasBose_Ed...
0 Points
2 Posts
Re: Dynamically Swapped UserControl: EventListeners of Buttons of UserControls are not firing
Apr 15, 2012 02:40 PM|LINK
I found the soultion. The problem is the ID of UserControlbeing added. I have modified two methods AddUserSettings and AddSpaceSettings in the following way:
private void AddUserSettings() { UserSettings settings = LoadControl("~/UserControls/UserSettings.ascx") as UserSettings; settings.ID = "usersetting"; AddSettings(settings); } private void AddSpaceSettings() { SpaceSettings settings = LoadControl("~/UserControls/SpaceSettings.ascx") as SpaceSettings; settings.ID = "spacesettings"; AddSettings(settings); }Now it is working.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Dynamically Swapped UserControl: EventListeners of Buttons of UserControls are not firing
Apr 17, 2012 01:45 AM|LINK
Congratulations!Welcome to our forum next time to share more solutions and talk with us about the technology of ASP.NET……