Question

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" %>
Was it helpful?

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>

OTHER TIPS

Check user control code if it contains a head element. Also check all dependencies to see if there are head elements present in them.

I think you have use <form id="formID" runat="server"> in both of your page and user Control .
Just remove runat="server" from your user Control Form tag .

Make sure you have in your user control cs file:

public partial class WebUserControl1 : System.Web.UI.UserControl

In ascx:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebUserControl1" %>

In aspx parent:

    <%@ Register  Src="WebUserControl1.ascx" TagPrefix="uc" TagName="WebUserControl1 " %>

 <uc:WebUserControl1  runat="server" ID="mycontrol" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top