locked
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

    <fieldset></fieldset>
    Friday, August 31, 2018 6:59 AM

All replies

  • User753101303 posted

    Hi,

    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">
        <title></title>
    </head>
    <body>
        <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>Philippines</asp:ListItem>
                <asp:ListItem>USA</asp:ListItem>
                <asp:ListItem>Canada</asp:ListItem>
                <asp:ListItem>New Zealand</asp:ListItem>
            </asp:ListBox>
            <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 />
        </form>
    </body>
    </html>
    

    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
      https://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.6.1"/>
        <httpRuntime targetFramework="4.6.1"/>
        
        <pages>
          <controls>
            <add tagPrefix="uc1" src="~/Guru99Control.ascx" tagName="Guru99Control"/>
          </controls>
        </pages>
        
      </system.web>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs"
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, 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=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
        </compilers>
      </system.codedom>
    
    </configuration>
    

    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