Asp.net basic questions

Source: Internet
Author: User

Differences between WebSite and WebApplication
1) when the background code is changed, WebApplication needs to restart the browser or regenerate the solution, while WebSite does not;
2) The WebSite has no Solution and no namespace, which is not conducive to engineering development.
How does HTTP work?
1) The client submits a form Request to process the Request.
2) Handle with the server-side Handler
3) Server Response
Note: The name attribute must be added to the form elements submitted to the server, because the server only recognizes the name, which is different from Jquery and DOM. They only recognize the id.
Question about the method attribute of Form specifying the Form submission method *
1) get (default value) is to explicitly pass the form through the URL in the address bar;
The form value passed by post is hidden in the Http message and invisible in the URL address bar;
2) The number of get passed values is limited and will be affected by the length of the address bar. It seems that the maximum value is 2 K bytes, and there is no limit on post.
3) When you refresh the page in post, a browser will prompt you to resubmit the form dialog box, but get will not.
What content in DIV is not submitted to the server?
The value of the name attribute (such as input, textarea, and select) of the div is submitted to the server.
ViewState Principle
1) hide some fields to store controls without value attribute values
2) because http is a stateless protocol, when the page changes, viewstate will be used to maintain the last page state.
3) For example, the label control is rendered by the browser as a <span> flag, so the label value exists in viewstate;
Similarly, the textbox Control is rendered by the browser as the input tag, and the values in the TextBox do not need to be stored. Because TextBox is essentially the input, the input will be submitted to the server without hiding the field.
4) You can use the ViewStateDecoder tool to view the appearance of the content in viewstate.
Advantages and disadvantages of storing status information in hidden fields (viewstate)
1) increase website traffic
2) reduced access speed
3) security issues (such as online banking) such as data spoofing may occur when confidential data is put into the form ). *
All background programs implement the IhttpHandler interface.
Both Cookie and session are used to store the data of the current client,
Cookies are stored on the client, and sessions are stored on the server.
Note: The session cannot store too much data. It stores object-type data, so you need to replace the data type during use.
Each type of elements on the page, such as img, js, and css, are requested separately when an http request is sent. This can be viewed through the developer tool or the well-known Firebug.
* Http is a "stateless" protocol, so it does not remember what it did last time, nor does it remember the last message sent to the browser. So when it re-Requests next time, img, js, css, and other files will re-send header information.
Get is transmitted explicitly through parameters transmitted in the url address bar, such :? A = 123 & B = abc
Post does not pass values through URLs, But it quietly transmits data in the background and uses _ VIEWSTATE for implicit transmission.
Meaning of various HTTP Status Codes
1) 200 series, indicating that the request is successful, OK
2) series 300, such as 307, indicates server redirection and further processing of requests is required;
3) Series 400, such as 404, indicates that the page is not found, file not found.
4) 500 series, indicating an internal server error.
The event submitted by the write delete Button in the background is to be added to the OnClientClick attribute in the Button control.
<Input type = "submit" name = "delete" value = "delete" OnClientClick = "return confirm ('Are you sure you want to delete it? ') "/>
A friendly operator can be prompted on the client to avoid unnecessary deletion.
127.0.0.0 is the loopback address, indicating that the local host cannot be accessed without passing through the nic and its alias is localhost.
0.0.0.0 indicates any IP address, AnyIP.
Convert Html and js to a common one-to-one character
HttpUtility. HtmlEncoder (string s) // convert to a special character. For example, convert <to <greater than sign>;
/Indicates the root directory of the website;
.. Indicates the parent directory;
. Indicates the current directory;
~ The special path, which is only used in the server control, indicates that it is defined from the root directory of the application.
Converts a virtual path to a full path, an absolute path
VirtualPathUtility, ToAblolute ("~ /A/B .html "); // convert to/WebSite/a/B .html
The server control must use the post method to submit the form.
You can use ClientID to obtain the client Control ID,
GetElementById ('<% = TextBox1.ClientID %> ');
Not the ID of each server control is the same as that of the client control. For example, in a custom control (WebUserContrl. ascx), the ID of the server control is different from that of the client.
The label of the server control is rendered to <span> on the client side. If the AssociateControlID attribute is set to TextBox1, it is rendered to <label for = "TextBox1 "... /> to achieve the focus of the associated control.
The Literal control does not render anything on the client and is displayed in plain text.
When the Mode attribute is set to EnCode, the control automatically implements HttpUtility. HtmlEncoder (string s) conversion, which is sometimes convenient and can avoid XXS attacks.
TextBox Control
1) when the TextMode attribute is set to SingleLine, it is rendered as <input type = "text"/>
2) When the TextMode attribute is set to MultiLine, it is rendered as <textarea/>
3) when the TextMode attribute is set to Pasword, it is rendered as <input type = "password"/>
4) when the AutoPostBack attribute is set to true, leaving the TextBox with the user focus will result in a page post. It is best to use the _ doPostBack js method when submitting a form.

The RadioButton control is rendered as <input type = "radio"/> on the client side. Like the server side control, the RadioButton control can also be grouped by the GroupName attribute.
The Button control is rendered on the client as <input type = "submit"/>
The LinkButton control is rendered on the client as <a href = "javascript :__ doPostBack"/>
The ImageButton control is a Button that allows you to set ImageUrl. It is rendered on the client as <input type = "image"/>
Similarities: You can set the OnClientClick attribute to "return confirm ('Are you sure you want to delete it? ')";
The Panel control is rendered as a DIV on the client. If the GroupingText attribute is set, the Panel control is rendered as <fieldset> <legend> Settings </legend> </fieldset>, that is, the GroupBox effect.
The Hyperlink control is rendered as a <a/> flag on the client.
You can set the properties NavigateUrl = "" and Target = "". If you set the ImageUrl attribute, it is rendered to <a href = ""> <image/> </a>.
The FileUpload control is rendered on the client as <input type = "file">.
Generally, the code for uploading files is written in this way.
If (FileUpload1.hasFile ())
{
String uploadPath = Server. MapPath ("~ /Upload /");
FileUpload1.SaveAs (uploadPath + FileUpload1.FileName );
}
In general, controls are divided into three types:
1) HTML controls
2) ASP. NET Server-side controls
3) HTML control with runat = "server"
Verify controls
1) RequireFieldValidator: A required field for non-empty server verification. common attributes include ErrorMessage, ControlToValidate, and InitialValue. you can write if (this. isValide ){...}
2) RangeValidator: determines whether the value is between the given maximum value (MaximumValue) and minimum value (MinimumValue). The comparable data types include string, int, and currency.
3) CompareValidator: used to compare whether the relationship between two values meets the requirements or data of the specified type. Comparison operators: <,>, = ,! =. Common attribute: ValueToCompare: Compare with which value, ControlToCompare: Compare with which control.
4) RegularExpressionValidator: a regular expression used to verify that the data meets the requirements. Common attribute: ValidationExpression: defines a regular expression.
5) CustomValidator: used for custom verification in special cases.
6) Note: (1) almost all verification controls must be verified on the client and server.
(2) group verification controls: ValidationGroup
(3) Whether to trigger the verification event: CauseValidation: false, indicating that the verification event is not triggered
(4) modify and verify whether the control is placeholder: Display is set to Dynamic or Static.
Data Binding
1) Example: <ItemTemplate> <% # Eval ("Id") %> </ItemTemplate>
2) The Repeater data control is used to bind the traversal display of data. Of course, you can also use the foreach statement to hand-Write the data.
3) Other Repeater control templates
(1) <AlternatingItemTemplate> set different styles of the row, that is, the style of the even row.
(2) The <HeadTemplate> and <FootTemplate> headers are displayed before and after the data, respectively, for example, <table> </table> or <ul> </ul> can be prevented.
(3) <SeperatorTemplate>, the delimiter between the two data items.
The database only stores the image path, ResolveClientUrl ("~ /Images/+ url ");
The controls placed in the <ItemTemplate> template cannot be operated directly in the c # code in the background. You must first find the controls by ID, such as e. Item. FindControl ("txtName ");
The Repeater control is generally used to display data only, while the ListView control is used to add, delete, change, and production operations.
Eval () is a one-way binding, used to read data in the database; Bind () is a two-way binding, which can read the values in the database to the page and upload user values to the database.
Considerations for the ListView control:
(1) automatically generated styles should be extracted into css styles rather than inline styles;
(2) in <ItemTemplate>, the <asp: Label> control is generally not required to display read-only data and output data directly.
(3) <LayoutTemplate> must have a server control with id itemPlaceHolder. Change the English fields automatically generated in the header to Chinese. Useless IDs must be deleted, and no need to be displayed.
Note the following in the ItemDataBound event:
(1) determine the data Row Type e. Item. ItemType = ListViewItemType. DataRow
(2) obtain the corresponding RowView ListViewDataItem lvDataItem = (ListViewDataItem) e. Item; DataRowView rowView = (DataRowView) lvDataItem. DataItem;
(3) When using FindControl, you should pay attention to the AlternatingItemTemplate problem.
Differences between ListView and GridView
(1) The GridView can only be rendered as a Table.
(2) ListView can be rendered to both Table and <ul> <li>
The DropDownList control binds the SelectedValue attribute, for example, SelectedValue = "<% # Eval ('txtname') %>"
If the page front-end does not involve adding, deleting, modifying, and querying interactive information, you can disable ViewState in either of the following ways:
(1) Disable ViewState on the page as a whole: Add EnabelViewState = "false" to the <page> label on the top"
(2) Disable ViewState for the specified control: Add EnabelViewState = "false" to the property of the control"
Website Performance Tuning
(1) Cache is the first method for optimizing website performance;
(2) Index is the first way to optimize database performance;
How to Set page cache: In the page header area, set <% @ OutputCache Duration = "20" VaryByParam = "none" (this is variable and can be set as a parameter: id; num; age, etc.) %>
The data cache setting method sets attributes for ObjectDataSource,
(1) EnableCaching = "True"
(2) CacheDuration = "20"

1 .! Whether ispostback () is loaded for the first time
2. All types of base class objects
3. config link string
<ConnectionStrings>
<Add name = "con" connectionString = "Data Source = IP address; Initial Catalog = database name; User ID = username; PassWord = PassWord" providerName = "System. data. sqlClient "/>
</ConnectionStrings>
4. ADO. NET5 basic objects
5. OA Office Automation ERP enterprise resource management WMS warehouse management system MIS Information Management System crm Customer Relationship Management
6. How to pass page values
Get Query
Post Modification
Put increase
Delete
7. Default class access type internal
8. Five main objects in ADO. NET
Connection object
The Connection object is mainly used to enable the Connection between the program and the database. You cannot obtain data from the database if you do not use the linked object to open the database. This object is at the bottom layer of ADO. NET. We can generate this object by ourselves or automatically generate it by other objects.

Command object
The Command object can be used to send commands to the database, such as sending query, addition, modification, and deletion commands to the database, as well as calling the stored programs in the database. This object is structured on the Connection object, that is, the Command object is linked to the data source through


DataAdapter object
The DataSetCommand object is used to transmit data between data sources and DataSet. It can issue commands through the Command object and put the obtained data into the DataSet object. This object is structured on the Command object and provides many functions used with DataSet. In Beta 2, The DataSetCommand object is renamed as DataAdapter.

DataSet object
The DataSet object can be regarded as a Cache, which can keep the data queried from the database and even display the whole database. DataSet can not only store multiple tables, but also obtain data Table structures such as primary keys through the DataSetCommand object and record the association between data tables. The DataSet object can be called ADO. NET heavyweight object, which is structured on the DataSetCommand object and does not have the ability to communicate with the data source itself. That is to say, we use the DataSetCommand object as a DataSet object and a bridge between data sources for data transmission.

DataReader object
You can use the DataReader object to read data in sequence instead of other operations. The DataReader object only reads data from the data source in a descending order, and the data is read-only and does not allow other operations. Because DataReader only reads one row at a time and can only be read-only, it not only saves resources but also improves efficiency. In addition to high efficiency, DataReader can reduce network load because it does not need to transmit all data.
9. // description


Big question
1. Differences between string stringbuilder
String repeated memory Application
Stringbuilder memory extension

2. Four access Modifiers
Public any other code in the same assembly or other assembly that references the Assembly can access this type or member.
Private only the code in the same class or structure can access this type or member.
Protected only the code in the same class or structure or derived class can access this type or member.
Any code in the same assembly of internal can access this type or member, but the code in other assembly cannot.
Protected internal any code in the same assembly or any derived class in other assembly can access this type or member.

3. viewstate, Session, cookie
ViewState only exists on the current page
Sessions are stored at the service end. The variable addresses in the sessions are different. each user has one address, which can be obtained on different interfaces. However, the memory space is limited and it is easy to lose.
The cookie is saved on the client. Others are the same as sessions.

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.