Click here to Skip to main content
16,017,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a user control MembersFoundControl.ascx that is loaded into the MembersControl.ascx when duplicate members are found. The MembersFoundControl control definition is:
<%@ Control Language="C#" AutoEventWireUp="true" CodeBehind="MembersFoundControl.ascx.cs" Inherits="MemberTrack2016.ControlClasses.MembersFoundControl" %>

It is registered in MembersControl as:
<%@ Register Src="~/ControlClasses/MembersFoundControl.ascx" TagPrefix="mfctrl" TagName="MembersFoundControl" %>

It is loaded into a placeholder in the MembersControl as
ASP.NET
MembersFoundControl memberListControl = LoadControl("~/ControlClasses/MembersFoundControl.ascx") as MembersFoundControl;
MembersFoundPlaceholder.Controls.Add(memberListControl);

the control events are defined in the MembersFoundControl as:
ASP.NET
<div id="MemberListActionDiv" class="ButtonDivStyle" style="width: 36em; padding-top: 1em; padding-bottom: 0.5em">
        <asp:button id="UseNewMemberButon" cssclass="MemberButtonStyleLarge" text="Use New Member" runat="server" onclick="OnUseNewMember">
        <asp:button id="MFC_CancelButton" cssclass="MemberButtonStyle" text="Cancel" runat="server" onclick="OnMFCCancel" style="margin-left: .625em">
    </div>

And the Event operations are in the MembersFoundControl.ascx.cs file
ASP.NET
protected void OnUseNewMember(object sender, EventArgs e)
        {
            MembersFoundEventArgs args = new MembersFoundEventArgs();
            args.nRetType = IDUSENEWMEMBER;
            args.MemberRec = null;
            args.nRelation = nRelationType;
            onUseThisMember(this, args);
        }

        protected void OnMFCCancel(object sender, EventArgs e)
        {
            MembersFoundEventArgs args = new MembersFoundEventArgs();
            args.nRetType = IDCANCEL;
            args.MemberRec = null;
            args.nRelation = nRelationType;
            onUseThisMember(this, args);
        }


When the control is loaded in the place holder the buttons are named and given the ids as follows:
ASP.NET
<div id="MemberListActionDiv" class="ButtonDivStyle" style="width: 36em; padding-top: 1em; padding-bottom: 0.5em"></div>

The event is not fired in either MembersFoundControl or in MembersControl.

This is built in Visual Studio 2017 (2019 has problems).

Does anyone have any suggestions? THANKS

What I have tried:

I have tried everything I can think of.
Posted
Updated 27-Jan-21 8:37am
v2

You need to recreate the controls on every postback. The best place to do that would be the Init event of the placeholder you're adding them to.

Dynamically Adding Wired Controls to Web Forms[^]

Remember, your page and the entire control hierarchy only exists until the HTML is rendered and returned to the user. The only controls which are automatically recreated when the page posts back are those which are declared in the markup. Any dynamically added controls will need to be recreated on every request.
 
Share this answer
 
v2
I am not sure what you mean. The initialization of a control is OnInit. This would meant that this would fire everytime the MembersContol is refreshed. And the lifecycle of the MembersFoundControl is only for the duration of selecting one of the members found. However, that said, I have tried that and it did not work because the ids of the buttons are attached to the MembersControl not the MembersFoundControl.

Can you give a further explanation regarding your solution, I may have missed something when I tried it?
 
Share this answer
 
Comments
Richard Deeming 28-Jan-21 4:15am    
If you want to ask for more information, click the "Have a Question or Comment?" button under the solution you're replying to and post a comment.

Do not post your comment as a new "solution".

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