用户控制VS服务器控件 [英] User control vs Server control

查看:190
本文介绍了用户控制VS服务器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解 HTML asp.net

看来(请的的纠正我,如果我错了!)的code我写上我的Web项目我的aspx页面是不是所有的HTML。相反,它们是由一些ASP.Net编译运行code当用户从他们的URL进行HTML请求(所以感谢 RUNAT服务器在编译理解非HTML标记,如< ASP )。然后 - 编译器使用此code到动态创建一个HTML页面。例如 - 这个转换一个按钮输入

It seems (please do correct me if I'm wrong!) that the code I write on my aspx pages on my web project are not all html. Rather, they're a code which is run by some "ASP.Net" compiler when a user makes an html request from their url (So thanks to runat server the "compiler" understands non-html tags such as <asp). Then – the "compiler" uses this code to create an html page on the fly. For example – this converts a Button to an input.

这是真的吗?如果是这样,那么,什么是用户控件?

Is this true? If so, then, what is a user control?

推荐答案

ASP.NET有服务器端控件(如按钮,超链接,GridView的等)。这些都产生可以通过C#/ VB.NET code来处理服务器端的事件(Button1_OnClick)。

ASP.NET has server side controls (Such as buttons, hyperlinks, gridviews etc). These all generate server side events (Button1_OnClick) which can be handled by C#/VB.NET code.

<asp:Button ID="btnCopyText" runat="server" /> // Calls the server side btnCopyText code

public void btnCopyText_Click(object sender, EventArgs e) {

}  

HTML有它自己的这是由客户端浏览器(客户端)。

HTML has it's own controls which are rendered by the client's browser (client side).

 <button onclick="copyText()">Copy Text</button> // Calls the copyText() function (Client Side)

在ASP.NET按钮被在服务器端渲染,然后被传递到客户端为标准的HTML按钮(如上图所示)。

The ASP.NET Button gets rendered at the server side and then gets passed down to the client as a standard HTML Button (Shown above).

一个自定义用户控件是由程序员创建ASP.NET服务器端控件,它可以包含多个ASP.NET服务器端控件,如GridView控件和一个按钮)。一个例子是,当点击该按钮时重新加载在GridView中的数据。这对于ASP.NET开发人员提供了一种方法来写一个自定义的控制,并在需要的时候,而不是编写样板code(重复同样的code)重用。

A custom user control is an ASP.NET Server Side control that is created by the programmer, it may contain several ASP.NET Server Side Controls such as a GridView and a button). An example would be, when the button is clicked it reloads the data in the GridView. This provides a way for an ASP.NET developer to write one custom control and reuse it when needed rather than write boilerplate code (repeating the same code).

http://msdn.microsoft.com/en-us/library/ y6wb1a0e.aspx

这篇关于用户控制VS服务器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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