为什么我们在asp.net中使用runat [英] Why we use runat in asp.net

查看:100
本文介绍了为什么我们在asp.net中使用runat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET的每个控件中我们使用runat =server

知道我们为什么这样做吗?

In every control of ASP.NET we use runat="server"
Do know why we do that?

推荐答案

Runat ='Server '表示在Serverside上控件的可访问性。



让我让你更清楚。



如果你把 runat =server在任何控件内,然后你可以在服务器上使用控件 side。



eg

Runat='Server' Indicates the accessibility of the control at Serverside.

Let Me make you more clear about it.

If you puts runat="server" inside any of the control then you can use that control at the server side.

e.g
<asp:TextBox id="txt" Runat="Server"></asp:TextBox>







string s = txt.Text;





你也可以访问喜欢





and you can also access Like

TextBox tBox = (TextBox)Page.FindControl("txt");





如果你不提供那么它将无法找到,因为服务器不知道谁是txt。





如果有帮助,请 投票 接受答复


您不需要通过在论坛中发布这些类型的问题来等待答案。一点点的谷歌搜索将在几秒钟内为您提供大量资源。



http://forums.asp.net/p/1609766/4112578.aspx [ ^ ]
You don't need to wait for answers for this type of questions by posting them in forum. A little googling will give you lots of resources within a few second.

http://forums.asp.net/p/1609766/4112578.aspx[^]


标签runat =server表示脚本块中包含的代码将在服务器上运行(和不在客户端)。在执行时,ASP.NET将创建包含此代码的服务器端对象以及Page类的实例,以包含在页面内定义的控件作为其给定类型的实例(System.Web.UI.WebControls.Textbox,例如)。此服务器端对象将根据用户请求调用,并将执行代码以响应事件。
Tag runat="server" indicates that the code contained within the script block will run on the server (and not on the client). On execution, ASP.NET will create server-side objects that contain this code as well as an instance of the Page class to contain the controls defined inside the page as instances of their given type (System.Web.UI.WebControls.Textbox, for example). This server-side object will be invoked on user request and will execute code in response to events.


这篇关于为什么我们在asp.net中使用runat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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