In ASP. NET development, the background and foreground interactions are often used. This section summarizes the methods for c # and Java script to operate on each other and Java script to call the c # method.
Call the Java script method in the c # code in the background
Java script code:
- <script type="text/javascript" language="javascript">
- function test()
- {
- alert("oec2003");
- return false;
- }
- </script>
C # code:
- protected void Button1_Click(object sender, EventArgs e)
- {
- ClientScript.RegisterStartupScript(this.GetType(), "clear",
"<script>test()</script>");
- }
Java script in ASP. NET calls the c # Method
If the method in c # has a return value, you can use the following method:
C # code
- public string GetAuthStatus()
- {
- ViewState["Auth"] = "Red";
- return ViewState["Auth"].ToString();
- }
Java script code
- function getAuth()
- {
- var authStatus="<%=GetAuthStatus()%>";
- return authStatus;
- }
In ASP. in NET, Java script calls the c # method without returning a value. You can put a button on one side and then write what you want to do in the Click Event of the button, write the following code in the client script.
- document.all("button1").click();
- ASP. NET TypeConverter
- Analysis on TypeResolver of ASP. NET
- Define JavaScriptConverter in ASP. NET
- How to replace Sys. Services in ASP. NET
- Use Profile Service of ASP. NET AJAX