Saturday, March 24, 2012

strange error in asp.net application using Web user control

Hi,

I made a webuser control which is a menu with some links. Now iam trying to add an asp drop downlist in the webuser control an it is giving me this error:

Control 'Menu1_DropDownList14' of type 'DropDownList' must be placed inside a form tag with runat=server.

I know that webuser control does not consists of the FORM tag so why is it giving me error:

Here is my code :

<%@dotnet.itags.org. Control Language="c#" AutoEventWireup="false" Codebehind="menu.ascx.cs" Inherits="Hospital.menu" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%
<DIV style="WIDTH: 170px; POSITION: relative; HEIGHT: 179px" ms_positioning="GridLayout"
<asp:HyperLink id="HyperLink1" style="Z-INDEX: 101; LEFT: 17px; POSITION: absolute; TOP: 11px" runat="server" ForeColor="ActiveCaptionText" NavigateUrl="testaspx.aspx" Font-Bold="True"
<span class="NormalBold">Add Patient</span></asp:HyperLink
<asp:HyperLink id="HyperLink2" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 94px" runat="server" ForeColor="ActiveCaption" NavigateUrl="AddVolunteer.aspx"
<span class="NormalBold">Add Volunteer</span></asp:HyperLink
<asp:HyperLink id="HyperLink3" style="Z-INDEX: 103; LEFT: 9px; POSITION: absolute; TOP: 129px" ForeColor="ActiveCaption" runat="server" NavigateUrl="VolunteerList.aspx"
<span class="NormalBold">List of Volunteers</span></asp:HyperLink
<asp:DropDownList id="DropDownList14" style="Z-INDEX: 104; LEFT: 24px; POSITION: absolute; TOP: 51px" Runat =server ></asp:DropDownList></DIV
------------------------You need to place the UserControl inside a form tag with RunAt=Server.
You need to place your User Control (ASCX) inside an ASPX page and, as Douglas points out, that ASPX page must wrap your user control inside <form runat="server"> ... </form> tags.

Like this:

<%@. Page Language="VB" Debug="true" %>
<%@. Register TagPrefix="my" TagName="UserControl" src="http://pics.10026.com/?src=mycontrol.ascx" %>
<html>
<head>
</head>
<body>
<form runat="server">
<my:UserControl id="myUserControl" runat="server"></my:UserControl>
</form>
</body>
</html>

Thanks a lot

0 comments:

Post a Comment