ASP. NET knowledge point summary-technical knowledge (1)

Source: Internet
Author: User

1. dynamically add JS scripts to webpages

In system. we. UI. the page contains two methods: registerstartupscript () and registerclientscriptblock (). You can dynamically add scripts to a webpage. They both contain two parameters: Key, script, and key, which are unique identifiers, script is a script block. The only difference between the two methods is that the location of the generated script block is different. Hey, it's twins. ------ the time of birth is different ---

2. Page jump Method

First, you can use the method in ASP to register a reference. <a href = "XX. aspx"> jump to page 2 </a>;
Second, you can use the hyperlink space to redirect the page by setting the navigatorurl attribute. The applicable scenario is when the user decides when to jump ---
Third, you can use response. redirect () method. The mechanism is that the server first sends an HTTP request to the client, notifies the client to reach a new page, and then the client sends a jump request to the server, the last page cannot access the content of the submitted Form on the previous page, but the session, application, and cookie objects can be used to access data between pages. Applicable situations: when you want to save the URL as a query string and jump to a webpage of a non-aspx type, you need to jump to the page of another server;
Fourth, you can use the server. Transfer Method. The special feature of this method lies in the fact that the server is willing to change the webpage. The client browser will not know the redirection, so the URL Information in the browser will not change. The original form and all session information can also be saved; suitable for page Jump on the same server, which can avoid unnecessary network communication and achieve better performance ---
Fifth, the server. excute () method is basically useless;

3. Implement page error custom redirect error page

A mermererror section is defined in Web. cinfig. The configuration is as follows:

<Cinfiguration> <system. web> <customererrors defaultredirect = "error. aspx "mode =" remoteonly "</system. web> </configuration> you must understand that mode represents the display mode. On is displayed on both the client and server, and remoteonly displays the custom page only on the client, when off, the initial debugging information page is displayed. <customererrors> </customererrors> allows the definition of <error statuscode = "404" Redirect = "XX. aspx "/> to achieve different redirection for different network errors, for example, 404 is not found, 401 is not authorized to access;

4. Web ApplicationsProgramShortcut

Each Web Server Control has an accesskey attribute, which allows you to access the control by using a shortcut key. However, you only need to focus on the Control. Only the button and imagebutton buttons have the keyboard Click Time;

5. Discussion about table controls

Table is a server-side control used for layout. Currently, div + CSS is popular, so table should be used as little as possible. Table is composed of rows and columns. Note that, table has the rows attribute to represent the array of all rows, but it does not have columns, but is replaced by cells () after adding the method to the control or text, call the add method of rows to add the method. It feels that the table is suitable for dynamic data display;

6. dynamically load controls on pages

Because of the relationship between the webpage layout, the placeholder control is often used when loading controls on a webpage. This control can be used as a container to dynamically load other controls for it. When using it, the control is generated dynamically and then added to the placeholder's controls collection. Note thatCodeThe created server control does not automatically save its information on the page. In other words, after the page is refreshed, all the states will be invisible. The solution is to compile the corresponding generated code in the pageload time, determine whether viewstate ["addcontrol"] is null. If it is not null, the button BTN = new button (); placeholder1.controls. add (BTN); BTN. id = "btn1"; the ID attribute is set to the ID of the dynamically generated control in the Code; when setting the control attribute, add the control to the controls set and then set it, prevents data loss after refreshing.

 

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.