ASP.Net controls globally in the web config configuration file asp. NEED HELP! RRS feed

  • Question

  • User1545944408 posted

    I tried this tutorial and yet it gives me an error.

    Im wondering why did I met this kind of error yet I did carefully follow the instruction of the tutorial step-by-step.

    This is the error that shows in my browser.

    Server Error in '/' Application.

    Parser Error

    Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

    Parser Error Message: The page '/demo.aspx' cannot use the user control '/Guru99Control.ascx', because it is registered in web.config and lives in the same directory as the page.

    Source Error: 

    Line 11: <body>
    Line 12:     <form id="form1" runat="server">
    Line 13:         <uc1:guru99control ID="Guru99Control1" runat="server" />
    Line 14:         <br />
    Line 15:         <br />

    Source File: /demo.aspx    Line: 13 

    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2623.0

    Friday, August 31, 2018 6:59 AM

All replies

  • User753101303 posted


    and lives in the same directory as the page

    Maybe the tutorial uses another directory to store them? I never had this issue but Im' storing theml in their own folder for convenience anyway...

    Friday, August 31, 2018 7:16 AM
  • User1545944408 posted

    this is the code that I have in my web form demo.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="demo.aspx.cs" Inherits="DemoApplication1.demo" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <form id="form1" runat="server">
            <uc1:guru99control ID="Guru99Control1" runat="server" />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <asp:Label ID="lblName" runat="server" Text="NAME"></asp:Label>
            <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            <br />
            <br />
            <asp:ListBox ID="lstLocation" runat="server">
                <asp:ListItem>New Zealand</asp:ListItem>
            <br />
            <br />
            <asp:RadioButton ID="rdMale" runat="server" Text="Male" />
            <asp:RadioButton ID="rdFemale" runat="server" Text="Female" />
            <br />
            <br />
            <asp:CheckBox ID="chkASP" runat="server" Text="ASP.NET" />
            <br />
            <asp:CheckBox ID="chkC" runat="server" Text="C#" />
            <br />
            <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />

    and this is the code for my web.config

    <?xml version="1.0" encoding="utf-8"?>
      For more information on how to configure your ASP.NET application, please visit
        <compilation debug="true" targetFramework="4.6.1"/>
        <httpRuntime targetFramework="4.6.1"/>
            <add tagPrefix="uc1" src="~/Guru99Control.ascx" tagName="Guru99Control"/>
          <compiler language="c#;cs;csharp" extension=".cs"
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>

    I dont know where I made a mistake, really. :'(

    Friday, August 31, 2018 8:02 AM
  • User409696431 posted

    If you register the controls in the web.config, they cannot be in the same directory as the page.  See the note on https://docs.microsoft.com/en-us/dotnet/api/system.web.configuration.tagprefixinfo?redirectedfrom=MSDN&view=netframework-4.7.2   (I assume there is a reason for this, but no explanation is given.  Just accept that it is by design.)

    You can move the controls into their own directory, for the easiest solution.

    Monday, September 3, 2018 5:36 AM