无法解析母版页页面加载的样式
我在链接到母版页的文件夹中有一个页面login.aspx。在母版页的页面加载事件中,我添加了一些样式。当我重定向到 login.aspx 时,它无法从母版页的页面加载事件中获取样式。我分析问题发现,因为我的login.aspx不在根文件夹中,而是在根文件夹内的文件夹中。
如何在login.aspx 中运行母版页的pageload 事件?
I have a page login.aspx in a folder which is linked to masterpage. In the page load event of masterpage I have added some styles. When I redirect to login.aspx, it is just not able to get the styles from the masterpage's pageload event. I analysed the problem found that because my login.aspx is not in root folder, but in a folder which is inside root folder.
How do I run masterpage's pageload event in login.aspx?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以将所有样式表放置在文件夹结构中,如下所示:
然后在内容 ASPX 页面中,只需将
Theme="Style"
添加到页面指令中,ASP.NET 就会自动为每个页面解析它你有:-)You can place all your style sheets in a folder structure as follows:
Then in your content ASPX pages, just add
Theme="Style"
to the page directives and ASP.NET will automatically resolve it for every page that you have :-)我假设您正在谈论 CSS 样式表,而不是 ASP.NET 样式(主题)。
在这种情况下,您可以在母版页中使用如下所示的标记:
或者您可以通过
Page_Load()
处理程序以编程方式插入相同的标记。但是,在这种情况下,最好将 HtmlLink 控件添加到 Head 控件。或者,您可以向控件添加 ID,并使用Visible="True"
来控制它是否出现在生成的标记中。I assume you're talking about CSS stylesheets, and not ASP.NET styles (themes).
In that case, you can using a tag like the following from your Master page:
Or you can insert the same tag programmatically from your
Page_Load()
handler. However, in that case, it's best if you add the HtmlLink control to the Head control. Alternatively, you can add an ID to the control and useVisible="True"
to control whether it appears in the generated markup.如果当您将代码移动到模板化页面(不是,而是使用它的页面)时代码有效,则表明您正在使用样式表的相对链接。
我建议使用根目录之外的相对 URL(“/stylesheet.css”形式的内容),这样当您有使用模板但位于子目录中的页面时,它可以正确解析样式表。
If the code works when you move the code to your templatized page (not the but the one that uses it) then it suggests that you are using a relative link for the stylesheet.
I'd recommend using a relative URL off the root (something in the form of "/stylesheet.css") so that when you have pages that use the template, but in a subdirectory, it can resolve the stylesheet correctly.
问题是标记部分位于母版页中,因此无法引用样式表
The problem is that the section of the markup is located in the Master Page, so the reference to the StyleSheet cannot be made