使用C#语言在asp.net中的标记中创建方法 [英] create a method in tag in asp.net with c# language

查看:85
本文介绍了使用C#语言在asp.net中的标记中创建方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用c#语言在asp.net中的标记<% %>中创建方法

How i can create a method in tag <% %> in asp.net with c# language

推荐答案

没有理由将方法定义放入aspx页.请为此使用文件后面的代码.这会使您的页面不必要地难以阅读.
只是我的两分钱!

如果您确实需要将方法定义放入aspx页面中,我真的很想听听您的解释. :)

干杯,

-MRB
There is no reason to put a method definition into an aspx page. Please use the code behind file for that. It would make your page unnescessarily hard to read.
Just my two cents!

If you feel you really have to put your method definition into an aspx page, I''d really like to hear your explanation. :)

Cheers,

-MRB


您可以在这些标记之间调用/调用c#方法,但不适用于创建方法.当使用返回结果的方法时,应使用<%=SomeMethod()%>,这将在执行时将其替换为结果.您可以在与网页关联的代码隐藏(.cs)文件中创建c#方法(如SomeMethod()).

附带说明一下,不可能在服务器上运行的控件中调用c#方法(这些控件具有runat="server"属性/值).

祝你好运!
You can call/invoke a c# method between those tags but are not for creating methods. When using a method that gives back a result you should use <%=SomeMethod()%>, this will replace this with the result when executed. You can create a c# method (like SomeMethod()) in the codebehind (.cs) file associated with your web page.

As side note, it isn''t possible to invoke a c# method in a control that runs on the server (those have the runat="server" attribute/value).

Good luck!


这取决于.有时可以,有时不能.如果要调用代码隐藏方法或使用代码隐藏变量,则必须执行以下操作:

It actualy depends. Sometimes, you can, sometimes you can''t. If you want to call a code-behind method or use a code-behind variable, a;ll you have to do is this:

<a href="<%=GetUrlForThisTag() %>">My Custom Url</a>



但是如果要在脚本标签中执行此操作,则不能执行以下操作:



but if you want to do it in a script tag, you can''t do this:

<script language="javascript">DoMyJavascriptFunction(''<%=GetUrlForThisTag() %>'')</script>


这篇关于使用C#语言在asp.net中的标记中创建方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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