Javascript 添加js文件并从C调用js函数#

Javascript 添加js文件并从C调用js函数#,javascript,c#,internet-explorer,browser-extension,Javascript,C#,Internet Explorer,Browser Extension,我正在使用C#开发一个IE插件。我在js文件中有javascript函数。我需要将js文件附加到C#,并从C#调用js函数,将值发送到js,它必须返回一个值 JS文件-sample.JS: function sample (str) { //js code } private void button1_Click(object sender, EventArgs e){ //Need to call sample(str) and pass 'str' value to the j

我正在使用C#开发一个IE插件。我在js文件中有javascript函数。我需要将js文件附加到C#,并从C#调用js函数,将值发送到js,它必须返回一个值

JS文件-sample.JS:

function sample (str) {
   //js code
}
private void button1_Click(object sender, EventArgs e){
   //Need to call sample(str) and pass 'str' value to the js function.
}
C#文件:

function sample (str) {
   //js code
}
private void button1_Click(object sender, EventArgs e){
   //Need to call sample(str) and pass 'str' value to the js function.
}
注:我尝试了下面的代码,但没有将对象引用设置为对象的实例

Page page = HttpContext.Current.CurrentHandler as Page;   
page.ClientScript.RegisterClientScriptInclude("sample","sample.js");
page.ClientScript.RegisterStartupScript(typeof(Page),"Test","<script type='text/javascript'>sample('str');</script>");
Page Page=HttpContext.Current.CurrentHandler作为页面;
page.ClientScript.RegisterClientScriptInclude(“sample”、“sample.js”);
page.ClientScript.RegisterStartupScript(typeof(page),“Test”,“sample('str');”;

当前,ASP.Net应用程序必须调用C#回调:

<asp:Button ID="button1" runat="server" Text="Do something" onclick="button1_Click" />

这完全取决于“
str
”参数值的来源,您希望将其传递给JavaScript函数…

可能的重复感谢。但是你能为上述情况推荐一个工作代码吗?代码中有什么错误?我只使用c#而不是asp.net。我正在使用addin express创建浏览器扩展。当我可以向js发送一个值并且它将返回另一个值时,您能用c#提供一个代码吗