Function methods in the execution of C # code in JavaScript functions summary _javascript tips

Source: Internet
Author: User

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
}

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.