简体   繁体   English

如何将母版页放置在ASP .NET Web项目中?

[英]Where to place master page in asp .net web project?

I have this folder structure in my project. 我的项目中有这个文件夹结构。 Web,WebControls along with other folders. Web,WebControls以及其他文件夹。 My .aspx pages are in Web folder and master page is in WebControls folder. 我的.aspx页位于Web文件夹中,而母版页位于WebControls文件夹中。 This has caused some problems. 这引起了一些问题。

  1. In anchor tags with href='#' and onclick='SomeJavascriptFunction', href value becomes /WebControls/# and this results in 404. 在带有href ='#'和onclick ='SomeJavascriptFunction'的锚标记中,href值变为/ WebControls /#,结果为404。
  2. In anchor tags href='SomeJavascriptFunction', when user clicks on the link, it looks for /Web/SomeJavascriptFunction and this is obviously not found there. 在锚点标签href ='SomeJavascriptFunction'中,当用户单击链接时,它将查找/ Web / SomeJavascriptFunction,但显然在此处找不到。

All I want to know is what is the best practice to place Master page in the project? 我只想知道在项目中放置母版页的最佳实践是什么? If I can go ahead with the present structure, how can I overcome above problems? 如果我可以按照目前的结构继续前进,该如何克服以上问题?

Thank you very much in advance. 提前非常感谢您。

As you're happy with the solution posted in the comments, I'm reproducing it here: 当您对评论中发布的解决方案感到满意时,我在这里复制它:

Where to leave the MasterPages: 离开母版页的位置:

  • There's no specific rules regarding that, but just leave them in the same folder you have the pages. 没有关于此的特定规则,只是将它们保留在页面所在的文件夹中。 It will make your life easier. 这将使您的生活更轻松。

How to get rid of the problems posted: 如何摆脱张贴的问题:

  • I wouldn't set the href attribute with the javascript function as it is. 我不会按原样使用javascript函数设置href属性。 I would rather do that: href="javascript:void()" onclick="myJavascriptFunction()" . 我宁愿这样做: href="javascript:void()" onclick="myJavascriptFunction()"

Why my Javascript function is returning undefined: 为什么我的Javascript函数返回未定义:

  • The document ready is used to attach event handlers, not to define functions. document readydocument ready用于附加事件处理程序,而不用于定义函数。 These should stay off this block. 这些应该远离这个障碍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM