简体   繁体   English

在ASP.NET中的同一页面上隐藏代码并内联?

[英]Codebehind and inline on same page in ASP.NET?

In ASP.NET, is it possible to use both code behind and inline on the same page? 在ASP.NET中,是否可以在同一页面上同时使用后台代码和内联代码? I want to add some inline code that's related to the UI of the page, the reason to make it inline is to make it easy to modify as it outputs some HTML which is why I don't want to add it in the code behind, is this possible in ASP.NET? 我想添加一些与页面的UI相关的内联代码,使其内联的原因是在输出一些HTML时易于修改,这就是为什么我不想在后面的代码中添加它,在ASP.NET中有可能吗?

Edit: I'm sorry, obviously my question wasn't very clear, what I meant is using a script block with runat="server", this is what I meant by inline code. 编辑:很抱歉,显然我的问题不是很清楚,我的意思是使用带有runat =“ server”的脚本块,这就是内联代码的意思。

Thanks 谢谢

Yes, you can use inline code just like in classic asp. 是的,您可以像经典asp中一样使用内联代码。 You can use 'this' or 'me' to get to the code behind fields, methods, etc. 您可以使用'this'或'me'来获取字段,方法等后面的代码。

Yes, that will work, make sure the code behind class is declared as a partial class, which is the default these days anyway. 是的,这将起作用,请确保将类后面的代码声明为局部类,无论如何这是当前的默认设置。 Don't think it would work in 1 or 1.1 不要认为它将在1或1.1中工作

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

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