Asp. NET service-side basic controls Introduction

Source: Internet
Author: User
Tags form post

The Lasp.net server-side control is an ASP. html wrapper, which can be used in C # code TXT1. text= ' abc ' This way to modify the value of input, ASP. NET turns the server-side control into HTML code output to the browser. The server-side control is a very attractive beginner, very easy to get started, and is also the most criticized things. The use of the service-side control of the network system, the background of the Internet system, and other areas of low frequency access is still very suitable. (Internet company, product Type Company (OA)) L properties written in the label of the server-side control if the property that is not built into the control is output to the client L all of the ASP. NET most of them are inherited from the control, WebControl class, and almost all of the members are: · (1) ClientID, the ID of the control on the client, the ID of the control on the server does not necessarily equal the ID in the client HTML, such as in a template for a control such as a ListView. So if you want to manipulate the control on the client through the JavaScript Dom, jquery's getElementById, $ ("#id"), it's best not to write the service-side ID directly, but $ (' #<%=txt1. Clientid%> '). Use the jquery event to set the different styles for the mouse to move over the control and away from the control. You can see the difference between the ClientID and the ID in the user control. UserControl, Master, ListView. It is recommended to always use the ClientID (2) Visible property, if the control is visible, and if Visible=false does not go to HTML, this is not the same as giving the element style.display= ' none ' effect in HTML. • (3) The CssClass property, the style name of the control, is the class property of the control in HTML. You can also modify properties such as BackColor, BorderStyle, and so on, but this is not recommended because there are a lot of inline styles that generate large HTML sizes and are not easy to modify uniformly. • (4) Attributes, which is used to set the extra properties of the get control. Is the same as setattribute (), getattribute () in the DOM. button1.attributes["A1"] = "2.jpg"; The HTML event appears on the server as a property button1.attributes["onmouseover"] = "alert (' Hello ')"; L Description: All server-side controls can use not only the properties defined by the control, but also the extra properties. These properties include HTML attributes that the control does not encapsulate (such as the ONmouseover such as browser-side event pages as attributes), ASP. NET renders its unrecognized properties to the client intact. Additional properties can also be set in code through the Attributes property: checkbox1.attributes["onmouseover"] = "alert (' Hello ')"; L1, Label control. The Text property is a display literal. The Associatedcontrolid property is used to associate a control that, if empty, is displayed as a <span&gt, and if specified as the ID of a control, it is displayed as a <Label> in an HTML and set the For property to the ClientID of the associated control. The L2, literal control also shows a piece of text, but the literal control does not render any extra tags, but it shows the value of the Text property. L3, TextBox control, text box control. The TextMode property values Singleline, MultiLine, Password, respectively, are rendered as input (Type=text), textarea, and input (Type=password). When the AutoPostBack property is true, the user focus leaves the textbox, which causes the page post, and the implementation principle is the AutoPostBack of the ASP. TextChanged event (requires Autopostback=true to be modified after the trigger, otherwise the page commits to trigger), the text changes when the event triggers. (Submit form as Post) it is best to call the __doPostBack method when you want to submit the form in ASP. The L4, RadioButton control, which corresponds to input (Type=radio), is grouped by groupname attribute L5, Button control. OnClientClick property, when the user clicks the button on the browser execution code, note that OnClientClick is a string attribute, the code is written in JavaScript code, run on the browser side. <asp:button id= "Btndel" runat= "Server" onclientclick= "return confirm (' Do you really want to delete it? ') "text=" Delete "/>l6, LinkButton, usage and button, the difference is that the button control renders as a button, and LinkButton renders as a hyperlink. Do not use LinkButton to achieve ordinary hyperlinks, because LinkButton's HREF is a piece of JavaScript code that does a form post and cannot "open a connection in a new window." And say "row delete" in that example, the href is the same as the JavaScript hyperlink principle. Generally with the button on the line, only the user asked "to become a hyperlink good" to adopt LinkButton, is a browser rendered as a hyperlink, the server as a button to use things. Lhyperlink:ispostback=false, no form content submitted, no onclick event. L7, ImageButton controls are also similar to buttons, except that they are displayed as pictures, rendering as input (Type=image) L8, Button, LinkButton, ImageButton and other controls have CommandName, CommandArgument two properties and command events, you can have multiple button controls share a command event handler by reading the event object E's CommandName, CommandArgument Two properties read the two parameters set on the Click button to perform a different operation. Example: editing and deleting multiple rows of data. This usage is most used in controls such as ListView. L9, panel controls are used to hold some controls. If you set the GroupingText property then it is rendered as a div tag with <fieldset>, which is the groupbox effect, otherwise rendered as &LT;DIV&GT;L10, Hyperlink control, hyperlink. Not the same as LinkButton (frequent test), not to the server-side post, is a hyperlink. NavigateURL: the link address; text: Displays the texts. If you set the ImageUrl property, a picture hyperlink is displayed. L11, fileupload control, File upload control. Render as input (Type=file). Properties: Filecontent The uploaded file as a stream; filename upload file name; HasFile bool value, indicating whether the user chooses a file, the SaveAs method is used to save the file to the specified location on disk. Vulnerability: File Upload Vulnerability (upload an aspx to download the source code, Process.Start start formatting, create an administrator, turn on Remote Desktop). Workaround: Only allow upload of the specified type of file, upload folder does not give execute permission. lhtml control, ASP. NET renders HTML controls as normal strings to the browser side, without checking for correctness and failing to process on the server side. Lasp.net server-side controls, with ASP. NET-Highly encapsulated controls, simple to use, run on the servers, and can use C # on the service sideThe code is rendered to the client as an HTML control. The Lrunat=server HTML control. Adding runat= "Server" on top of the HTML control is also run on the server side, or it can be manipulated by the service side using C # code and rendered to the client, not as highly encapsulated as the ASP. NET service-side controls, and the exposed properties are mostly ordinary HTML attributes. The benefit compared to the ASP. Runat=server HTML control is handy when you need to manipulate the control on the server side, if the control is not encapsulated by the ASP. runat= The server's HTML control also handles virtual paths (~/), Id→clientid, so Onmouseover= "document.getElementById (') may be used in the use of virtual paths, UserControl. <%=TextBox1.ClientID%> '). value= ' haha '; I have a problem directly in the property, will output the <% directly to the browser side, so do not write in the control's property values <%%>. Lrun=server the benefits of HTML controls, the Golden mean! L1, unlike the ASP. NET service-side controls, so many heavyweight, packaged, programmers can better control the quality of the generated content. Easier for artists to use because the artist does not recognize &LT;ASP:TEXTBOXL2, relative to HTML controls:

1) ability to manipulate controls in server-side code

2) Ability to automatically process virtual paths ~

3) can handle ClientID.

L Select Order: html→run=server html→asp.net server Control La→htmlanchor;form→htmlform;head→htmlhead;input→htmlinputbutton, HtmlInputCheckBox, HtmlInputText, etc; Meta→htmlmeta;table→htmltable;tr→htmltablerow;td→htmltablecell ; Title→htmltitle. Labels that are not individually encapsulated (such as DIV) or custom labels (such as MMM) correspond to the type HtmlGenericControl. Use the Attributes property to manipulate an unpackaged property. L don't have to remember it alone, forget it, get a label in ASPX and try it out. L The server-side HTML control is not as advanced as the ASP. NET control, such as the bgcolor property of the ASP. HTML control is a color type, and the bgcolor property of the text is a string type, which requires the developer to set a valid value L data binding is divided intoData SourceAnddata-bound controlsTwo parts, the data-bound control through the data source to obtain the data, through the data source to isolate the data provider and the data consumer, the data binding control through the data source to modify the data, the data source has SqlDataSource, AccessDataSource, ObjectDataSource, LinqDataSource, EntityDataSource, XmlDataSource, etc. (SiteMapDataSource is a sitemap dedicated data source), Because most projects do not directly connect to the database (because it violates the most basic layering principle), SqlDataSource, AccessDataSource will not be used, LinqDataSource, EntityDataSource is also only used in very extreme projects that use LINQ, EF, and XmlDataSource is only possible when working with XML data. ObjectDataSource is the most widely used data source in web development, and it can easily be used for database switching. Data-bound controls have list data-bound controls (DropDownList, RadioButtonList, ListBox, CheckBoxList, BulletedList, and so on) and complex controls (DataGrid, GridView, DetailsView, FormView, ListView, Repeater, DataList, etc., the GridView is a subset of the ListView). The DataGrid is deprecated in complex controls, Repeater is the most lightweight component, with the most in the front of the Internet, and the ListView is the GridView, DetailsView, FormView, Repeater, DataList, the unification of those controls, the benefits of those controls are all in the ListView, and the ListView controls are used, so the data-bound controls mainly talk about list data-bound controls, repeater, and ListView, which are used in the project. , Gridviewlobjectdatasource is used to make a class A data source, the TypeName property is the full name of the data source class, has DeleteMethod (delete method), InsertMethod (new method), SelectMethod ( Query method), UpdateMethod (Modify method) and several other properties, respectively, delete, insert, query, update the method name of the data in the class, these methods may have parameters, the value of the parameter is through DeleteParameters, UpdateParameters, InsertparaSet by nested nodes such as meters. Lobjectdatasource access to their own written ordinary class, labeled on the class [DataObject] Dataobjectmethodl hand-written ObjectDataSource too cumbersome, using a visual interface to complete. You can configure the ObjectDataSource by dragging and dropping it onto the interface and selecting "Configure Data Source" on the smart flag in the upper-right corner. Data source class General Typenameadapter class, select the class, select Next, respectively, select the corresponding method to get, delete, UPDATE, insert data. Ldropdownlist shows the data from ObjectDataSource, select the data source (DataSourceID property) for just the ObjectDataSource, and set the Display field (DataTextField) and the Value field (DataValueField). RadioButtonList, ListBox, CheckBoxList, BulletedList and so on are also used. L Set the binding manually, in addition to data binding (recommended) for setting a data source for the DataSourceID property of the control, you can also set the binding in code through code (the old version of ASP. NET can only be bound in this way, not recommended in the new version). • Code binding allows you to bind any object that implements the IEnumerable interface to a data-bound control. Listbox2.datasource = new object[]{3,5,6}; Listbox2.databind (); • Because data-bound controls save data in ViewState by default, the data will not be reloaded every time the page is refreshed, only the first time it needs to be loaded (! IsPostBack) • Because code binding has a lot of trouble with disabling ViewState, it is recommended to use DataSourceID to determine whether the data should be re-acquired. Ldropdownlist the original "Please select Gender" and the coexistence of data binding items: Appenddatabounditems= "true" to add data-bound items to the back.        

ASP. NET Server-side basic control introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.