TRICK:ASPX页面中的方法< %%>代码块 [英] TRICK: methods in ASPX pages with <%%> code blocks

查看:83
本文介绍了TRICK:ASPX页面中的方法< %%>代码块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


有什么好的理由不允许ASPX页面中的方法我不能想象,但是这里是如何得到的围绕这个限制:


(开始)

< body MS_POSITIONING =" FlowLayout">


< form id =" Form1"方法= QUOT;交" runat =" server">

<%

MyMethod(__输出);

%>

< / form>

< / body>

< / html>

<%

}

void MyMethod(System.Web.UI.HtmlTextWriter __output){

%>< input type =" text"命名= QUOT;姓名" value =" some html" /><%

%>

(END)


这是怎么回事:


ASP.NET将您的ASPX代码插入到隐藏的Render

方法中,该方法将HtmlTextWriter作为参数


我们使用"}"关闭当前渲染方法

然后声明一个采用相同参数的方法

我们不需要设置一个右括号,因为ASP.NET将

为我们做这件事

解决方案

" John Rivers" <音响***** @ btinternet.com>写在

新闻:11 ********************** @ g49g2000cwa.googlegr psps.com:

有什么好的理由不允许ASPX页面中的方法我无法想象,但这里是如何解决这个限制:




这会产生混乱的代码吗?


-

Lucas Tam(RE ******** @ rogers.com)

请删除删除来自回复时的电子邮件地址。
http://成员。 ebay.com/aboutme/coolspot18/


我的经典ASP并不凌乱

这是一套很棒的课程渲染html

处理多品牌

执行一流的最佳实践数据表和表格

具有完全锁定和运行的安全性全速

并且可以快速轻松地测试


什么是凌乱的是一堆UserControl文件

错过了面向对象编程的所有好处

让我的ASPX页面充满凌乱的寄存器标签

和非标准化属性访问


a UserControl只是文件中的一种方法

而不是它所属的类


这很傻!


谁说你在页面里没有方法?


你在< script runat =" server">< / server"


中的方法正如有人提到的,即使你能做到这一点,你也不应该这样做。有

是没有理由你不能把它放在文件后面的代码中,或者在类库中

DLL。


John Rivers <音响***** @ btinternet.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...

你好,

有什么好的理由不允许ASPX页面中的方法我无法想象,但这里是如何解决这个限制:

(START)
< body MS_POSITIONING =" FlowLayout">

< form id =" Form1"方法= QUOT;交" runat =" server">
<%
MyMethod(__输出);
%>
< / form>
< / body>
< / html>
<%
}
void MyMethod(System.Web.UI.HtmlTextWriter __output){
%>< input type =" ;文本"命名= QUOT;姓名" value =" some html" /><%
%>
(END)

这是如何工作的:

ASP.NET获取您的ASPX代码并将其插入隐藏的Render
方法,该方法将HtmlTextWriter作为参数

我们使用"}"关闭当前的渲染方法
然后声明一个采用相同参数的方法
我们不需要放置一个右大括号因为ASP.NET会为我们这样做


Hello,

What good reason there is for not allowing methods in ASPX pages I
can''t imagine, but here is how to get around that limitation:

(START)
<body MS_POSITIONING="FlowLayout">

<form id="Form1" method="post" runat="server">
<%
MyMethod(__output);
%>
</form>
</body>
</html>
<%
}
void MyMethod(System.Web.UI.HtmlTextWriter __output) {
%><input type="text" name="Name" value="some html"/><%
%>
(END)

how this works:

ASP.NET takes your ASPX code and inserts it into a hidden Render
method that takes HtmlTextWriter as an argument

we use "}" to close the current render method
then declare a method that takes the same argument
we don''t need to put a closing brace because ASP.NET will
do that for us

解决方案

"John Rivers" <fi*****@btinternet.com> wrote in
news:11**********************@g49g2000cwa.googlegr oups.com:

What good reason there is for not allowing methods in ASPX pages I
can''t imagine, but here is how to get around that limitation:



It makes for messy code?

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/


My Classic ASP isn''t messy
it is a beautiful set of classes that render html
handles multi-branding
perform top-notch best-of-practice datasheets and forms
with full locking and security that run at full speed
and can be tested quickly and easily

what IS messy is a bunch of "UserControl" files
which miss out on all the benefits of object oriented programming
leave my ASPX pages full of messy register tags
and non-standardised property accesses

a UserControl is just a single method in a file
instead of in a class where it belongs

it is silly!


Who says you can''t have methods in the page?

Just put your methods in <script runat="server"></server"

And as someone mentioned, even though you can do this, you shouldn''t. There
is no reason you can''t put it in a code behind file, or in a class library
DLL.

"John Rivers" <fi*****@btinternet.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...

Hello,

What good reason there is for not allowing methods in ASPX pages I
can''t imagine, but here is how to get around that limitation:

(START)
<body MS_POSITIONING="FlowLayout">

<form id="Form1" method="post" runat="server">
<%
MyMethod(__output);
%>
</form>
</body>
</html>
<%
}
void MyMethod(System.Web.UI.HtmlTextWriter __output) {
%><input type="text" name="Name" value="some html"/><%
%>
(END)

how this works:

ASP.NET takes your ASPX code and inserts it into a hidden Render
method that takes HtmlTextWriter as an argument

we use "}" to close the current render method
then declare a method that takes the same argument
we don''t need to put a closing brace because ASP.NET will
do that for us



这篇关于TRICK:ASPX页面中的方法&lt; %%&gt;代码块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆