Search code examples
c#asp.net.netweb-controls

UserControl in asp .net is not working?


I have created a two usercontrols in asp.net and one webform . Now i want these two usercontrols to show in form in webform but it say that there must be one head with runat="server"

this is webform where i am using UserControl!

            <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Light.master"  CodeBehind="AdministrationPage.aspx.cs" Inherits="DXApplication5.AdministrationPage" %>
        <%@ Register src="~/AdminPage/AssignmentTab.ascx" tagname="AssignmentUC" tagprefix="uc1" %>
          <asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
        <table border="0">

<tr>
<td>
<div class="accountHeader">
     <uc1:AssignmentUC ID="CalendarUserControl1" runat="server" />  
</div>
</td>
</tr>
</table>

</asp:Content>

This is UserControl below:

<%@ Control Language="C#"  ClassName="AssignmentUC" AutoEventWireup="true" CodeBehind="AssignmentTab.ascx.cs" Inherits="DXApplication5.AdminPage.AssignmentTab" %>

Solution

  • I would add a single form to your masterpage, this may be the cause of your error.

    I would also remove all other form server controls from your user controls and pages.

    Try these steps:

    1. Go to Light.master master page file and make sure that this is in there somewhere <form id="form1" runat="server"> and a closing tag, the id may be different.
    2. Go to the following files AssignmentTab.ascx and AdministrationPage.aspx and remove any <form id="form1" runat="server"> and closing tags </form>