Several similar marker symbols in asp: <%=...%><%#...%><%%><%@%> Interpretation and usage
A: <% #%>: is executed when the bound control DataBind () method is executed for data binding
such as: <% # Container.DataItem ("tit")%>
<%=%>: Called during program execution to display background variable values
Such as:
*.aspx: <%= AAA%>
*.cs: Protected string aaa= "name";
<%%>: Inline code blocks can be embedded in the page file *.aspx or *.ascx file inside the background code
Such as:
<%
for (int i=0;i<100;i++)
{
Reaponse.write (i.ToString ());
}
%>
<%@%> is the front code import namespace on *.aspx page,
Such as:
<%@ importnamespace= "System.Data"%>
1.JavaScript accessing C # functions
2.JavaScript accessing C # variables
Access to existing variables in JavaScript in 3.c#
4. How to access JavaScript functions in C #
JavaScript access to C # functions
method One,
1, first set up a button, in the background will be called or processed content written in Button_Click;
2, write a JS function in the foreground, the content is document.getElementById ("Btn1"). Click ();
3, in the foreground or background call JS function, fire click event, equal access to the background C # function;
method Two,
1.
function declared as public or protected
2, in the HTML with <%=fucntion ()%> can call
method Three,
<script language= "JavaScript" > Function __doPostBack (eventtarget, eventargument) {var frontform = document. Form1; Refers to runat=server form frontform.__eventtarget.value = Eventtarget; Frontform.__eventargument.value = eventargument; Frontform.submit (); } </script> <input id= "Button1" type= "button" Name= "Button1" value= "button" onclick= "Javascript:__dopostback (' Button1 ', ') ' >
Accessing C # Variables in JavaScript
Method One: 1, through the page hidden domain access <input id= "xx" type= "hidden"
runat= "Server" >
Method Two: 1, if the background defines the public STRING
N; The format of the variable referenced in the foreground JS is ' <%=n%> ' or ' +<%=n%>+ '
Method Three: 1, or you can register a script on the page after the server-side variable is assigned a value
"<script language= ' JavaScript ' >var
temp= "+ tmp +" </script> "
TMP is a background variable, and then JS can directly access the temp to get the value.
Existing variables for accessing JavaScript in C #
Method One: 1. The foreground uses the static text control to hide the field and writes the value of the JS variable to it;
2, backstage with request["id" to get the value;
Method Two: You can use a cookie or session
accessing JavaScript functions in C #
Method One: 1, page.registerstartupscript ("GGG", "<script>setvisible (1);</script>");
Method Two: Use the literal class, and then
ASP. Before and after the call method