User controls inside web part

Ashutosh Pandey asked on June 15, 2020 18:28

Is it a good practice to use a user control inside a web part?

User control itself inherits from CMSAbstractWebPart.

We have a user control inside an update panel which is inside a web part, something like this:

<%@ Register Src="~/CMSWebParts/Custom/SomeUserControl/Add.ascx" TagPrefix="ucsfl" TagName="SomeControl" %>


<cms:CMSUpdatePanel ID="udpReading" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
       <ucsfl:SomeControl runat="server" ID="someID" />
       ... some other html code ...

The user control itself has an update panel with a link button.

<cms:CMSUpdatePanel runat="server" ID="AddToFavoritesUpdatePanel" UpdateMode="Conditional">
      <asp:LinkButton ID="lnkAdd" runat="server" OnClick="lnkAdd_Click"></asp:LinkButton>
      <asp:AsyncPostBackTrigger ControlID="lnkAdd" EventName="Click" />

The problem is, when the lnkAdd button is clicked, the whole web part loads as an AJAX call instead of loading only the user control. The code on link button simply adds a record in database.

What are we doing wrong here?

Recent Answers

Ashutosh Pandey answered on June 16, 2020 19:41

Looks like this link has some answer, can you please help me understand it more.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.