Method One:
1. First establish a button, in the background will call or processing content written to Button_Click;
2, in the foreground to write a JS function, content for document.getElementById ("BTN1"). Click ();
3, in the foreground or backstage call JS function, fire click event, equal access to the background C # function;
Method Two: 1, function declared as public
Background code (change public to protected also can)
The following is a reference fragment:
Copy Code code as follows:
public string SS ()
{
Return ("a");
}
2, in HTML with <%=fucntion ()%> can call
Foreground script
The following is a reference fragment:
Copy Code code as follows:
<script language=javascript>
var a = "<%=ss ()%>";
alert (a);
</script>
Method Three: 1, <!--inject Script filtered-->
The following is a reference fragment:
Copy Code code as follows:
<script language= "JavaScript" >
<!--
function __doPostBack (Eventtarget, eventargument)
{
var theform = document. Form1; Refers to the form of runat=server
Theform.__eventtarget.value = Eventtarget;
Thefrom.__eventargument.value = eventargument;
Theform.submit ();
}
-->
</script>
<input id= "Button1" type= "button" Name= "Button1" value= "button" onclick= "Javascript:__dopostback (' Button1 ', ')" >
Method Four:
The following is a reference fragment:
Copy Code code as follows:
<script language= "JavaScript" >
function Submitkeyclick ()
{
if (Event.keycode = 13)
{
Event.cancelbubble = true;
Event.returnvalue = false;
Document.all.funname.value= "The function name you want to call";
Document.form[0].submit ();
}
}
</script>
<input onkeypress= "Submitkeyclick ()" id= "AAA" type= "text" >
<input type= "hidden" name= "Funname" >〈! --To store the function you want to call--〉
In the. cs there are:
The following is a reference fragment:
Copy Code code as follows:
Public Page_onload ()
{
if (! Page.ispost ())
{
String strfunname=request.form["Funname"]!=null? request.form["Funname"]: "";
Decide which function to call based on the returned value
Switch (strfunname)
{
Case "Enter ()":
Enter (); Call this function
Break
Case "Other":
Calling other functions
Break
Default
Calling the default function
Break
}
}
}
public void Enter ()
{
...... Like calculating a value
}