ASP.NET:背后code或后面没有code? [英] ASP.NET: Code behind or no code behind?

查看:240
本文介绍了ASP.NET:背后code或后面没有code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会有人要不要使用code隐藏文件,使服务器片面code都标记分开吗?并不是说应该是.NET超过传统的ASP?

Why would anyone want to not use a code behind file so that server sided code is separated from markup? Wasn't that supposed to be one of the advantages of .NET over classic ASP?

我个人认为,混合code与标记使得codeA很多更难理解。

Personally, I think mixing code with markup makes the code a lot harder to understand.

我讨厌看到那些混账<%%>(服务器面块)相互拼接与标记,呸。我希望这是ASP.NET仅仅是为了和传统的ASP向后兼容性,但我看到从MS的例子所有包括黄方括号的时间。

I hate to see those darn <% %> (server sided blocks) inter-spliced in with markup, yuck. I would expect that this is in ASP.NET solely for backward compatibility with Classic ASP but I see examples from MS all the time that include those yellow brackets.

我想了解哪些是可以在这里下载一个code例如和不解,为什么我的任何服务器片面中断显示这里执行的时候不破即使我看到已在web.config中设置code。由于我平时用code-屁股的工作,我想知道是否有一些关于服务器端code在处理不同的ASPX是$ P $调试从RUNAT =服务器$ C $ pventing我℃。

I am trying to understand a code example which is available for download here and puzzled at why any of my server-sided breaks shown here don't break when executing the code even though I see that has been set in the web.config. Since I usually work with code-behinds, I am wondering if there is something about server-side code in the aspx that is handled differently that is preventing me from debugging the runat=server code.

所以。我的问题是:

1)为什么会有人要不要使用code隐藏文件,使服务器片面code都标记分开吗?

1) Why would anyone want to not use a code behind file so that server sided code is separated from markup?

2)为什么会我无法打破服务器片面的逻辑?

2) Why might I not be able to break on the server sided logic?

您的见解和意见,也欢迎对我的任何相关评论。

Your insight and opinions are also welcomed on any of my related comments.

推荐答案

使用内联code能力&LT; %%&GT; 不只是为了向后兼容,但.NET的一个功能,可以允许一些(相对!)明确和直接的解决方案。它然而常常用在比理想的方式更小。同样,code在code-后面如果经常(一般在事实上)的一个不太理想的方式使用,因为是网络的控制。

The inline code ability using <% %> is not just for backward compatibility, but a feature of .NET that can allow for some (relatively!) clear and straightforward solutions. It is however often used in a less than ideal way. Likewise, code in the code-behind if often (usually in fact) used in a less than ideal way, as are web-controls.

有code在code-背后通常不用于独立的担忧,但已经混乱的意大利面条code在不同的地方比我们有它在传统的ASP。 .NET确实让你有非常良好的组织的解决方案,但它是由你来做到这一点。有code在页面背后code是不可以首次在这一旅程的步骤,只是在那里的旅程就开始了。

Having code in the code-behind typically does not serve to separate concerns, but to have jumbled spaghetti code in a different place than we had it in classic asp. .NET does allow you to have very well organized solutions, but it's up to you to make it happen. Having code in code behind pages is not the first step in that journey, just where that journey can begin.

至于为什么你的事件不被解雇,最有可能的:

As to why your events are not firing, most likely:

  • 在该事件实际上没有被触发。 (你改变的下拉列表中选择的项目,实际上触发该事件?)
  • 您实际上并不具备的情况下连接起来。在属性窗口的控制,是对应于讨论的事件中列出的事件函数的名字吗? (这是最直接的方法,你也可以使用的手柄的keywork在VB为例)
  • 在很多时候,当我的事件不解雇,是因为我在做一些愚蠢的事好像没有开始我的code,或者我的网址指向了错误的地方。
  • The event is not actually being triggered. (Are you changes the selected item in the drop-down list, to actually trigger that event?)
  • You do not actually have the event wired up. In the properties window for that control, is the event function name listed corresponding to the event in question? (this is the most straightforward way; you can also use the handles keywork in vb, for example)
  • Often when my events are not firing, it because I'm doing something stupid like not having started my code, or my url is pointing to the wrong place.

这篇关于ASP.NET:背后code或后面没有code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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