Question: 1. How do I access C # functions in JavaScript? 2. How do I access C # variables in JavaScript? 3. How do I access the existing variables of JavaScript in C #? 4. How do I access JavaScript functions in C #?
The answer to question 1 is as follows:
To execute functions in C # code in JavaScript functions:
Method One: 1, first establishes a button, in the backstage will call or the processing content writes in the 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)
public string ss()
{
return("a");
}
2, in the HTML used to call
Foreground script
<script language=javascript>
var a = "<%=ss()%>";
alert(a);
</script>
Method Three: 1,
<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument)
{
var theForm = document.Form1; //指runat=server的form
theForm.__EVENTTARGET.value = eventTarget;
theFrom.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
-->
</script>
<input id="Button1" type="button" name="Button1" value="按钮" onclick="javascript:__doPostBack(’Button1’,’’)">