asp.net Web Control reviews

Source: Internet
Author: User
Tags object end html form html tags net client
asp.net the control is divided into two categories, respectively, under the System.Web.UI.WebControls System.Web.UI.HtmlControls namespace, the former inherits from the WebControl, the latter inherits from the HTMLControl, These two classes are all inherited from System.Web.UI.Control, Windows platform, no matter what kind of development you are engaged in, eventually you need someone to call Loadlibrary.dll. Then the ASP.net control, no matter what control you use, will eventually call render. In fact, as a foreground developer, most of these controls are not as useful.

1. A long long ID will be generated first, especially when the face is set with controls, and one will let you end up with the HTML code
Expansion, and JS with the time to die in trouble, and JS interaction need to write a bunch of <%=control.clientid%>, no way, asp.net to ' good ' help us resolve ID conflicts
The problem. Why is this ID not separated from the resulting ID, probably because JavaScript was not as powerful as it was when you made the control, and was ignored by Ms.

2. There is also a problem of more than one span, that is, not the same, and not conducive to typesetting. When you write CSS, consider the span that is sandwiched between the awkward.

3.form problem, many forms, such as controls, to use the server-side form, when there are more than one form, you can only have some of the form with JS interaction, form in the URL rewrite
There is also a problem that is not generated after the URL redirection path, server-side processing this needs to rewrite the form

4. For beginners There are long _viewstate

Most of the time, when we write the foreground code, we just need to show it simply, don't need a long ID, no span, no _viewstate, just a few lines of clean
HTML tags, but there is no option or property settings, either all to you, or none at all. Although we can write code like ASP, and ASP.net, since we provide
It's always going to be used.

WebControl also brings some flexibility, now asp.net web development, basically are n-tier architecture, if the code is in the logical layer output,
Do not modify the source code can not be changed, <asp:hyperlink runat= "server" id= "link" > Connection text </asp:HyperLink> such as, simple to change the connection text
Templates, and so on. In addition, table controls are also quite handy for editing data in the background. But used in the foreground, the GridView, such as design into the art of cutting pictures, absolute physical activity.
Some people use control are fast obsessive-compulsive disorder, the front desk simple display to use the GridView, clearly StringBuilder patchwork and concise, and efficient mody.

A few days ago encountered a strange problem, want to do an effect, the mouse moved to the picture, highlighting the border, art to add to the code, anyway no effect, find half a day do not know how to return

Things, and then inadvertently found all the Image control, automatically added style= "border-width:0px;", well, back at the station Image.Attributes.Remove ("style");
Still have style= "border-width:0px;" In addition to the Image.Attributes.Clear (), there are still style= "border-width:0px", which is a design of the brain residue, presumably to

Solve the border of the IMG tag default 1px in a tag, but there is no way to use CSS to deal with the border attribute of image.


My most common controls:

Literal is clean and convenient. Piece of HTML code, JS code

Repeater Clean List

Placeholder Control display Logic

The most cerebral remnants of the control:

Image reason see above one

The least valuable control:

Label span sets literal on the line, the style to the art to solve, see no practical value.

Hard to use controls:

DataList, the GridView generates DIV or list layout is tired (only refers to the foreground)

Other controls vary depending on the situation.

In addition, the difference between HTMLControl and WebControl, there is such a saying on the internet, is completely misleading, really can't see anymore, explain
--------------------------------
1. It is also quite handy to use, for example, a button is generated:
HTML control is a huge collection of controls to all of the page, which function to use, set the properties, as follows:
<input Type=submit/button/text runat=server>
This takes up a significant amount of control resources
--------------------------------
This is purely misleading, and it is widely circulated. The end is to generate HTML tags, input and the like does not need to be a large collection of controls to get the page, but only the final generation of a label, to say the difference, but also just HTMLControl and webcontrol the difference between the base class.

--------------------------------
The 2.Web control has a loopback capability to maintain the state of the control with viewstate.
HTML controls cannot, and when clicked on the page, their status is lost.
--------------------------------
protected virtual void LoadViewState (object savedstate);
Protected virtual Object SaveViewState ()
In fact, these two definitions are in the System.Web.UI.Control base class, but the WebControl rewrite the two methods, but HTMLControl does not rewrite the two methods, but that's not the same as the above argument.

--------------------------------
3. The biggest difference between HTML controls and Web controls is that they differ in how the event is handled. For HTML form controls,
When an event is raised, the browser handles it. However, for Web controls, events are generated only by the browser, but browsing
Device does not process it, the client sends a message to the server telling the server to handle the event.
--------------------------------
This is confusing server events and client script events, whether implemented from WebControl or HTMLControl to trigger server-side events
Handling server-side events is possible as long as you implement the controls for the IPostBackEventHandler interface.



Related Article

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.