Question

I am looking for the best way to template a user control, so that when I specify a mode say readonly, edit, update, insert then the user control changes its mode correspondingly.

I have identified some methods and what I am looking for is a much elegant solution.

  • Create a form view in the page and specify insert, edit template as separate user control and load accordingly.

  • Create a form view inside user control and specify separate controls for edit/ insert for the records.

  • Find a way to template the user control so that when I specify the mode, when init ing a user control it will load appropriately into the page.

    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
      <asp:FormView  DefaultMode="ReadOnly" ID="FormView1" runat="server"> 
        <ItemTemplate>
        <name:user ID="User1" Visible="true"  runat="server" />
        </ItemTemplate>
        <EditItemTemplate>
         <name:user ID="User2" Visible="true"  runat="server" />
        </EditItemTemplate>
    </asp:FormView>
    

Please share your views on how this is done in normal scenarios; with just one user control and user control changing state based on Mode( a single user control and not 3 user controls for functions).

Was it helpful?

Solution

Try to use MultiView ASP.NET control. You can simply set up different views of your content and switch between these views whenever you like.

Here is some tutorial http://www.youtube.com/watch?v=YV5w7sgojm0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top