I want to build my own "code behind" like pages so that i can have HTML in a HTML file and code in cs file but be able to have Intellesense for the tokens in the HTML file. (i know that's what the .NET page class does, but i want to have something much lighter)
我想构建我自己的“代码隐藏”之类的页面,这样我就可以在HTML文件中使用HTML并在cs文件中使用代码,但是可以在HTML文件中使用Intellesense作为标记。 (我知道这是.NET页面类的功能,但我希望有更轻松的东西)
EG: in the .html file:
EG:在.html文件中:
<%@ Directive classname="HTMLSnippet" %>
<html>
<body>
<div>[%message%]
</body>
</html>
and in a .cs file
并在.cs文件中
public class MyClass : HTMLSnippet
{
public class MyClass () {
snippet.message = "message goes here"
}
}
So my question is how do make the HTMLSnippet class so that it's members are automatically created, and specifically show up in Intellesense as i add tokens to the .html file?
所以我的问题是如何制作HTMLSnippet类以便它的成员被自动创建,并且特别是在我添加令牌到.html文件时出现在Intellesense中?
I know that .net currently does it by creating the designer.cs file and basically builds a class with all the elements from the page as it goes, and that would work fine but how can i get visual studio to generate that before compiling so that it shows up in Intellesense. Thanks!
我知道.net目前通过创建designer.cs文件来实现它,并且基本上构建了一个包含页面中所有元素的类,并且这样可以正常工作但是如何在编译之前让visual studio生成它以便它出现在Intellesense中。谢谢!
Clarification I'm not using this as a handler yet, i want to use this to have HTML snippets with tokens be usable in code as an object with properties. so almost like a custom control. I think what i have to do is create a VS add-in that waits for me to type tokens into an .html file then it automatically creates a .cs file with members for each token.
澄清我还没有使用它作为处理程序,我想使用它来使代码的HTML片段在代码中可用作具有属性的对象。所以几乎像一个自定义控件。我想我要做的是创建一个VS加载项,等待我将标记键入.html文件,然后它会自动创建一个.cs文件,其中包含每个标记的成员。
5 个解决方案
#1
First, there is not a lot of bloat in an ASPX page, if you don't want the bloat. You can get rid of pretty much everything other than the @ Page directive tag. You can turn off viewstate, as well, if you do not want bloat on the client side, so I see no reason to reinvent the wheel.
首先,如果你不想要膨胀,ASPX页面中没有太大的膨胀。除了@Page指令标记之外,你可以除掉几乎所有东西。你可以关闭viewstate,如果你不想在客户端膨胀,所以我认为没有理由重新发明*。
If you want far less bloat, consider ASP.NET MVC. If I am guessing correctly, you will see the RTM at MIX, as Microsoft loves to release things at conferences. If not, it is RC2, so RTM is not that far away. In ASP.NET MVC, the ASPX pages can be extremely thin, as they are just views.
如果你想要更少的膨胀,请考虑ASP.NET MVC。如果我正确猜测,你会在MIX上看到RTM,因为微软喜欢在会议上发布内容。如果没有,它是RC2,所以RTM并不是那么遥远。在ASP.NET MVC中,ASPX页面可能非常薄,因为它们只是视图。
If you want to tackle this your own way, you can do what you want with HTTP Handlers to handle the type. I would not leave it as .htm or .html, as you will make it so you cannot serve a standard .html file on your server, which is not good. This solves the handling issue, which is only half your battle.
如果您想以自己的方式解决这个问题,可以使用HTTP处理程序来处理类型。我不会把它留作.htm或.html,因为你会这样做,所以你不能在服务器上提供标准的.html文件,这是不好的。这解决了处理问题,这只是你战斗的一半。
I am not sure the best way to handle Intellisense. One way is to reference, as shown on Stagner's blog: http://weblogs.asp.net/joestagner/archive/2008/05/12/add-custom-javascript-intellisense.aspx
我不确定处理Intellisense的最佳方法。一种方法是参考,如Stagner的博客所示:http://weblogs.asp.net/joestagner/archive/2008/05/12/add-custom-javascript-intellisense.aspx
I have not tried this with custom extensions, although it should work. You can also create your own custom XSD (XML) file, ala: http://vyasashutosh.blogspot.com/2007/05/providing-custom-intellisense-in-vsnet.html
我没有尝试使用自定义扩展,虽然它应该工作。您还可以创建自己的自定义XSD(XML)文件,ala:http://vyasashutosh.blogspot.com/2007/05/providing-custom-intellisense-in-vsnet.html
Personally, I would use the ASPX model and thin out what you don't need. you can even whack the templates if you would like so you can do this with every page. You cannot get rid of the @ page directive, but if that is too much bloat, I am not sure ASP.NET is the model you wish to work with.
就个人而言,我会使用ASPX模型并减少你不需要的东西。如果您愿意,您甚至可以打开模板,这样您就可以对每个页面执行此操作。你无法摆脱@ page指令,但如果这太过臃肿,我不确定ASP.NET是你想要使用的模型。
#2
Not that i agree with you, but you can create protected variables on code behind and use them the way you are trying.
不是我同意你,但你可以在后面的代码上创建受保护的变量,并按照你的方式使用它们。
At code Behind:
在代码背后:
protected string myVar1 = "Hello World"
At Html:
<html>
<body>
<div><%= myVar1 %>
</body>
</html>
Again, I just want to make it clear that working this way is going one step back and I advise against it.
再说一遍,我只想说清楚,以这种方式工作是退一步,我建议反对它。
#3
Try MVC framework.
尝试MVC框架。
else use PHP, DJANGO, ROR or some other framework that supports templates fully.
否则使用PHP,DJANGO,ROR或其他完全支持模板的框架。
#4
I believe if you inherit your class from the abstract UI.TemplateControl, you will get this functionality. I'm browsing through the interfaces to see if simply implementing a specific interface will get this for you, but, I'm guessing if you want this functionality this is what you'll need to do.
我相信如果你从抽象的UI.TemplateControl继承你的类,你将获得这个功能。我正在浏览界面,看看是否只是实现一个特定的界面就可以得到这个,但是,我猜你是否想要这个功能,这就是你需要做的。
#5
Or try using spark for asp.net it attempts to remove the need for inline script tags by using xml markup IE
或者尝试使用spark for asp.net,它试图通过使用xml标记IE来消除对内联脚本标记的需求
<% foreach( string key in collectionOfItems.Keys ) %>
<div><% =key %></div>
<% } %>
becomes something like
变得像
<foreachcollectionOfItems.Keys >
<div>$key</div>
</foreach>
note my example is better crap and wrong but you get the idea. google it... spark
请注意我的例子是更好的废话和错误,但你明白了。 google it ... spark
#1
First, there is not a lot of bloat in an ASPX page, if you don't want the bloat. You can get rid of pretty much everything other than the @ Page directive tag. You can turn off viewstate, as well, if you do not want bloat on the client side, so I see no reason to reinvent the wheel.
首先,如果你不想要膨胀,ASPX页面中没有太大的膨胀。除了@Page指令标记之外,你可以除掉几乎所有东西。你可以关闭viewstate,如果你不想在客户端膨胀,所以我认为没有理由重新发明*。
If you want far less bloat, consider ASP.NET MVC. If I am guessing correctly, you will see the RTM at MIX, as Microsoft loves to release things at conferences. If not, it is RC2, so RTM is not that far away. In ASP.NET MVC, the ASPX pages can be extremely thin, as they are just views.
如果你想要更少的膨胀,请考虑ASP.NET MVC。如果我正确猜测,你会在MIX上看到RTM,因为微软喜欢在会议上发布内容。如果没有,它是RC2,所以RTM并不是那么遥远。在ASP.NET MVC中,ASPX页面可能非常薄,因为它们只是视图。
If you want to tackle this your own way, you can do what you want with HTTP Handlers to handle the type. I would not leave it as .htm or .html, as you will make it so you cannot serve a standard .html file on your server, which is not good. This solves the handling issue, which is only half your battle.
如果您想以自己的方式解决这个问题,可以使用HTTP处理程序来处理类型。我不会把它留作.htm或.html,因为你会这样做,所以你不能在服务器上提供标准的.html文件,这是不好的。这解决了处理问题,这只是你战斗的一半。
I am not sure the best way to handle Intellisense. One way is to reference, as shown on Stagner's blog: http://weblogs.asp.net/joestagner/archive/2008/05/12/add-custom-javascript-intellisense.aspx
我不确定处理Intellisense的最佳方法。一种方法是参考,如Stagner的博客所示:http://weblogs.asp.net/joestagner/archive/2008/05/12/add-custom-javascript-intellisense.aspx
I have not tried this with custom extensions, although it should work. You can also create your own custom XSD (XML) file, ala: http://vyasashutosh.blogspot.com/2007/05/providing-custom-intellisense-in-vsnet.html
我没有尝试使用自定义扩展,虽然它应该工作。您还可以创建自己的自定义XSD(XML)文件,ala:http://vyasashutosh.blogspot.com/2007/05/providing-custom-intellisense-in-vsnet.html
Personally, I would use the ASPX model and thin out what you don't need. you can even whack the templates if you would like so you can do this with every page. You cannot get rid of the @ page directive, but if that is too much bloat, I am not sure ASP.NET is the model you wish to work with.
就个人而言,我会使用ASPX模型并减少你不需要的东西。如果您愿意,您甚至可以打开模板,这样您就可以对每个页面执行此操作。你无法摆脱@ page指令,但如果这太过臃肿,我不确定ASP.NET是你想要使用的模型。
#2
Not that i agree with you, but you can create protected variables on code behind and use them the way you are trying.
不是我同意你,但你可以在后面的代码上创建受保护的变量,并按照你的方式使用它们。
At code Behind:
在代码背后:
protected string myVar1 = "Hello World"
At Html:
<html>
<body>
<div><%= myVar1 %>
</body>
</html>
Again, I just want to make it clear that working this way is going one step back and I advise against it.
再说一遍,我只想说清楚,以这种方式工作是退一步,我建议反对它。
#3
Try MVC framework.
尝试MVC框架。
else use PHP, DJANGO, ROR or some other framework that supports templates fully.
否则使用PHP,DJANGO,ROR或其他完全支持模板的框架。
#4
I believe if you inherit your class from the abstract UI.TemplateControl, you will get this functionality. I'm browsing through the interfaces to see if simply implementing a specific interface will get this for you, but, I'm guessing if you want this functionality this is what you'll need to do.
我相信如果你从抽象的UI.TemplateControl继承你的类,你将获得这个功能。我正在浏览界面,看看是否只是实现一个特定的界面就可以得到这个,但是,我猜你是否想要这个功能,这就是你需要做的。
#5
Or try using spark for asp.net it attempts to remove the need for inline script tags by using xml markup IE
或者尝试使用spark for asp.net,它试图通过使用xml标记IE来消除对内联脚本标记的需求
<% foreach( string key in collectionOfItems.Keys ) %>
<div><% =key %></div>
<% } %>
becomes something like
变得像
<foreachcollectionOfItems.Keys >
<div>$key</div>
</foreach>
note my example is better crap and wrong but you get the idea. google it... spark
请注意我的例子是更好的废话和错误,但你明白了。 google it ... spark