C# 如何使用标记注册将 .ascx 文件导入 .aspx 页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/991797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I import a .ascx file into a .aspx page using tag registering?
提问by
I have this set up...
我有这个设置...
<%@ Register TagPrefix="UserControl"
TagName="UserLogin"
Src="~/admin/Authentication/Login.ascx" %>
<%@ Register TagPrefix="UserControl"
TagName="UserRegister"
Src="~/admin/Authentication/Register.ascx" %>
Then later on in the same file I use the tags...
然后稍后在同一个文件中我使用标签......
<div id="LoginContainer"><UserControl:UserLogin runat="server /></div>
<div id="RegisterContainer"><UserControl:UserRegister runat="server" /></div>
And for some reason, the UserControl:UserRegister gets underlined in green, when I hover over it, it says "Element 'UserRegister' is not a known element. This can occur if there is a compilation error in the website or if the web.config file is missing."
出于某种原因,UserControl:UserRegister 带有绿色下划线,当我将鼠标悬停在它上面时,它说“元素 'UserRegister' 不是已知元素。如果网站中存在编译错误或 Web.配置文件丢失。”
Is there something else I need to do to make these tags work other than just registering them at the top of the page?
除了在页面顶部注册它们之外,我还需要做些什么来使这些标签起作用?
回答by Amr Elgarhy
No, You did everything.
不,你做了一切。
What you want to make sure from are:
您要确保的是:
1- Build your project.
1- 构建您的项目。
2- Make sure there are no errors in the controls.
2- 确保控件中没有错误。
3- Make sure there is no errors in the web.config.
3- 确保 web.config 中没有错误。
4- Make sure from the paths you wrote in the Register line that it points to the right controls.
4- 确保从您在注册行中写入的路径指向正确的控件。
And try to run the web page, may be VS cache something and keeps it green underlined, so try to see the page in run mode.
并尝试运行网页,可能是VS缓存了一些东西并保持绿色下划线,所以尝试在运行模式下查看页面。
回答by ichiban
The tag is registration is correct. The error is self-explanatory.
标签注册正确。该错误是不言自明的。
"Element 'UserRegister' is not a known element. This can occur if there is a compilation error in the website or if the web.config file is missing."
“元素‘UserRegister’不是已知元素。如果网站中存在编译错误或缺少 web.config 文件,就会发生这种情况。”
Build your project and check where the compilation errors for the usercontrols are.
构建您的项目并检查用户控件的编译错误在哪里。
回答by Jason
What I found to work on my project was to delete the file *.aspx.designer.cs. When I did this is, it resolved the error I was having with my controls not being recognized.
我发现对我的项目起作用的是删除文件 *.aspx.designer.cs。当我这样做时,它解决了我的控件无法识别的错误。