为什么要使用<%=%> ? [英] Why use <%= %> ?

查看:61
本文介绍了为什么要使用<%=%> ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


新手提醒,请耐心等待< g>


我是ASP Classic,我们习惯使用技巧比如...


<%= strName%>


将动态内容插入HTML块。在ASP.NET中,你有各种各样的控件,比如看起来做同样事情的标签,但是

更多的功能和灵活性。如果是这样,是否有任何理由使用<%=

%>在什么时候?


我只是在问我正在阅读ASP.NET Unleashed时,他用这个显示了一个

的例子。我不明白他为什么不只是使用一个控件。授予他的

例子就像...


< body bgcolor ="<%= strColour%>">


他在哪里包含了一个标签的属性,而不是一个整个标签,

但是他已经提到了一个只生成基本的通用控件

文字而不是标签,为什么不用呢?


TIA


-

Alan Silver

(此行下方添加的任何内容都与我无关)

Hello,

Newbie alert, so please be patient <g>

I ASP Classic, we were used to using tricks like ...

<%=strName%>

to insert dynamic content into an HTML block. In ASP.NET, you have
various controls like the label that seem to do the same thing, but with
much more power and flexibility. If so, is there any reason to use <%=
%> at all?

I only ask as I am reading ASP.NET Unleashed, and he shows an example of
using this. I couldn''t see why he didn''t just use a control. Granted his
example was something like ...

<body bgcolor="<%=strColour%>">

where he was including an attribute for a tag, rather than a whole tag,
but he already mentioned a generic control that just produced the basic
text rather than a tag, so why not use that?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)

推荐答案

Alan:

你是对的,几乎从来没有一个好理由喜欢<%=%>用

使用控件。真<%=%>可能需要几纳秒的时间,但你需要支付

的价格(大约10倍)以及维护和错误。希望这本书是

,只是表明你可以做到这一点。你可能会有非常奇怪的场合

。最近有人询问如何创建< base>标签...在ifrst我

以为只使用< base id =" x" RUNAT = QUOT;服务器" />并将其声明为

HtmlGenericControl ...但事实证明< base> CAN''T有一个结束标记,并且

所有服务器/ html控件都呈现一个结束标记。我为这个人提供了一个

服务器控件来覆盖结束标签的行为,但使用<%=%>

可能是一个更容易使用的解决方案供他使用......还有其他的,

虽然我可以一手掌握它们,但场合......


Karl


-

我的ASP.Net教程
http://www.openmymind.net/

" Alan Silver" <人********* @ nospam.thanx>在消息中写道

news:gO ************** @ nospamthankyou.spam ...
Alan:
You are right, there''s almost never a good reason to prefer <%= %> over
using controls. True <%= %> might be nanoseconds faster, but you pay the
price (about 10x over) with maintenance and bugs. Hopefully the book was
just showing that you COULD do it. There might be very odd occasions were
you want to. Someone recently asked how to create a <base> tag...at ifrst I
thought just use <base id="x" runat="server" /> and declare it as an
HtmlGenericControl...but it turns out <base> CAN''T have a closing tag, and
all server/html controls render a closing tag. I provided the guy with a
server control which overwrote the closing tag behaviour, but using <%= %>
might have been an easier solution for him to use...There have been other,
although I can probably count them on a single hand, occasions...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:gO**************@nospamthankyou.spam...
你好,
<新手警报,所以请耐心等待我是ASP经典,我们习惯使用像...这样的技巧......

<%= strName% >

将动态内容插入HTML块。在ASP.NET中,你有各种各样的控件,比如看起来做同样事情的标签,但具有更强大的功能和灵活性。如果是这样,是否有任何理由使用<%=
%>什么?

我只是在问我正在阅读ASP.NET Unleashed时,他展示了一个使用它的例子。我不明白他为什么不只是使用一个控件。当然,他的
例子是......

< body bgcolor ="<%= strColour%>">

他在哪里包括标签的属性,而不是整个标签,
但是他已经提到了一个通用控件,它只生成基本的文本而不是标签,那么为什么不使用它呢?

TIA

- Alan Silver
(此行下面添加的任何内容都与我无关)
Hello,

Newbie alert, so please be patient <g>

I ASP Classic, we were used to using tricks like ...

<%=strName%>

to insert dynamic content into an HTML block. In ASP.NET, you have
various controls like the label that seem to do the same thing, but with
much more power and flexibility. If so, is there any reason to use <%=
%> at all?

I only ask as I am reading ASP.NET Unleashed, and he shows an example of
using this. I couldn''t see why he didn''t just use a control. Granted his
example was something like ...

<body bgcolor="<%=strColour%>">

where he was including an attribute for a tag, rather than a whole tag,
but he already mentioned a generic control that just produced the basic
text rather than a tag, so why not use that?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)



很好的例子。 asp.net中没有任何内容代表< body>标签,所以使用

<%...是合适的。你可以替换< body>使用通用控件(然后

,最终会得到两个< body>)。此外,您可能更喜欢保留旧的asp

风格。


Eliyahu


" Alan Silver" <人********* @ nospam.thanx>在消息中写道

news:gO ************** @ nospamthankyou.spam ...
Good example. There is nothing in asp.net representing <body> tag, so use of
<%... is appropriate. You can replace <body> with a generic control (then
you will end up with two <body>). Also you might prefer keeping your old asp
style.

Eliyahu

"Alan Silver" <al*********@nospam.thanx> wrote in message
news:gO**************@nospamthankyou.spam...
你好,
<新手警报,所以请耐心等待我是ASP经典,我们习惯使用像...这样的技巧......

<%= strName% >

将动态内容插入HTML块。在ASP.NET中,你有各种各样的控件,比如看起来做同样事情的标签,但具有更强大的功能和灵活性。如果是这样,是否有任何理由使用<%=
%>什么?

我只是在问我正在阅读ASP.NET Unleashed时,他展示了一个使用它的例子。我不明白他为什么不只是使用一个控件。当然,他的
例子是......

< body bgcolor ="<%= strColour%>">

他在哪里包括标签的属性,而不是整个标签,
但是他已经提到了一个通用控件,它只生成基本的文本而不是标签,那么为什么不使用它呢?

TIA

- Alan Silver
(此行下面添加的任何内容都与我无关)
Hello,

Newbie alert, so please be patient <g>

I ASP Classic, we were used to using tricks like ...

<%=strName%>

to insert dynamic content into an HTML block. In ASP.NET, you have
various controls like the label that seem to do the same thing, but with
much more power and flexibility. If so, is there any reason to use <%=
%> at all?

I only ask as I am reading ASP.NET Unleashed, and he shows an example of
using this. I couldn''t see why he didn''t just use a control. Granted his
example was something like ...

<body bgcolor="<%=strColour%>">

where he was including an attribute for a tag, rather than a whole tag,
but he already mentioned a generic control that just produced the basic
text rather than a tag, so why not use that?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)



> Alan:
你说得对,几乎没有理由偏爱<%=%>
使用控件。真<%=%>可能是纳秒更快,但你付出了维护和错误的价格(大约10倍)。希望这本书只是表明你可以做到这一点。


好​​吧,我猜它没有必要(通常​​),但它确实很好

确认。

你可能会有非常奇怪的场合。最近有人询问如何创建< base>标签...在ifrst我想只需使用< base id =" x" RUNAT = QUOT;服务器" />并将其声明为
HtmlGenericControl ...但事实证明< base> CAN''T有一个结束标记,并且
所有服务器/ html控件都呈现结束标记。我为这个人提供了一个
服务器控件来覆盖关闭标签的行为,但使用<%=%>
可能是一个更容易使用的解决方案......还有其他的,
虽然我可以一手掌握它们,但是场合...
You are right, there''s almost never a good reason to prefer <%= %> over
using controls. True <%= %> might be nanoseconds faster, but you pay the
price (about 10x over) with maintenance and bugs. Hopefully the book was
just showing that you COULD do it.
OK, I guessed it wasn''t necessary (usually), but it''s nice tohave it
confirmed.
There might be very odd occasions were
you want to. Someone recently asked how to create a <base> tag...at ifrst I
thought just use <base id="x" runat="server" /> and declare it as an
HtmlGenericControl...but it turns out <base> CAN''T have a closing tag, and
all server/html controls render a closing tag. I provided the guy with a
server control which overwrote the closing tag behaviour, but using <%= %>
might have been an easier solution for him to use...There have been other,
although I can probably count them on a single hand, occasions...




好​​吧,原谅无知,因为我真的是*新的这个,但我想我读了一个通用控件只是产生了你输入的b / b
,这可能是纯文本。如果我是对的,那么你不能用那个

代替吗?或者你不能在标签内使用控件吗?刚发生在我身上

我打字这可能行不通。


谢谢


- -

Alan Silver

(此行下面添加的任何内容都与我无关)



OK, forgive the ignorance as I''m *really* new at this, but I think I
read that one of the generic controls just produces pretty much what you
put in, which could be plain text. If I''m right, then can''t you use that
instead? Or can''t you use a control inside a tag? Just occurred to me as
I''m typing that this might not work.

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)


这篇关于为什么要使用&lt;%=%&gt; ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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