The farthest distance in the world Is not from the United States to China! It is China Telecom to China Netcom!
The most difficult thing to grasp in the world is not the use of a certain language! But details!
I.. Net code processing mechanism!
ASP. NET is different from ASP page processing mechanism!
The code in ASP <% xxx %> is compiled together with the code of other page languages.
While. Net first processes the code in <%> or the code in. Net itself during page loading.
After all the processing is completed, it is sent to the front-end page at a time, and then JavaScript and HTML are compiled;
As follows:
Front page code
<HTML>
<Head>
<Title>. Net Processing Process </title>
<Script language = JavaScript>
Function demo ()
{
For (VAR I = 0; I <= 20; I ++)
{
VaR get_id = <% = get_id ('I') %>; // get the value returned by C #
Document. getelementbyid (get_id );
}
}
</SCRIPT>
</Head>
<Body>
</Body>
</Html>
Methods In the background. CS code
Public String get_id (string ID)
{
String get_id = ID;
Result_id = xxxxxxxxxxxxxxxx // processing method omitted
Return result;
}
After reading this code, it is theoretically "correct", but you will find that the above Code is incorrect during actual operation, because the I value is always '123'
Why!
As mentioned above, because. NET must first process the code in <%> and then process the. NET code before sending it to Js for processing.
Therefore, I in <% = get_id ('I') %> before sending to JS is the ASCII code result! That is, 105. Therefore, the output is always the result of passing in 105.
That is to say, when the page is loaded, the CLR takes <% = get_id ('I') %> for processing, so that he does not process js to change the I value first.
After <% = get_id ('20140901') %> is processed, the result code is changed
<Script language = JavaScript>
Function demo ()
{
For (VAR I = 0; I <= 20; I ++)
{
VaR get_id = <% = get_id ('20140901') %>; // obtain the value returned by C #
Document. getelementbyid (get_id );
}
}
</SCRIPT>
The results are not what you want!
Ii. When to use stringbullder and small details using stringbullder
When system. String is assigned a value, a copy of the string type is created dynamically.
It changes itself into your value assignment, but dynamically creates a new memory space and creates a string copy, which affects efficiency, in particular, when processing strings in large quantities and converting strings in different formats.
Stringbullder directly assigns values to the original stringbullder object, which is much more efficient than string dynamic creation!
This is their difference! Hey!
However, stringbullder has a small detail.
I recently used stringbullder in a small project, but I found that his code is not very good in stringbullder writing.
.
Stringbullder sb = new stringbullder ();
SB. append ('<SCRIPT> ');
SB. append ('alert ('cute dummies )');
SB. append ('</SCRIPT> ');
In fact, this method does not fully utilize its advantages, because the script and the <number and> number do not belong to the same type.
During the Assembly, when the above operations are performed, the format conversion object packing operation is performed when. sb. append (<SCRIPT> );
To improve efficiency, we should separate string and other characters and write them in the following form:
Stringbullder sb = new stringbullder ();
SB. append ('<');
SB. append ('script ');
SB. append ('> ');
SB. append ('alert ');
SB. append ('(');
SB. append ('cute dump ');
SB. append (')');
SB. append ('</');
SB. append ('script ');
SB. append ('> ');
Don't worry!
III:
. <% =... %> And <% #... %> are different:
<% =... %> Is called when the program is executed, and <% #... %> is called after the databind () method
4. asp. net2.0 can enable the dialog box without adding attrbute.
A new onclientclick is added.
<Asp: button id = "btnclick" runat = "server" onclientclick = "Return confirm ('Are you sure? '); "Text =" button "> </ASP: button>
V. @ usage
@ Is often used before a variable to get the address. @ in C # is used before the string variable to ignore all escape characters in the string "\". For example:
Console. writeln ("C: \ downloads \ test.rar ");
It is equivalent to the following statement:
Console. writeln (@ "C: \ downloads \ test.rar ");
Interns are all cheering. Haha!