Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何在c语言设计的网站中使用javascript#_Asp.net - Fatal编程技术网

Asp.net 如何在c语言设计的网站中使用javascript#

Asp.net 如何在c语言设计的网站中使用javascript#,asp.net,Asp.net,**我如何在我的网站上写下由c#设计的java代码 txt=“浏览器代码名:”+navigator.appCodeName+“”; txt+=“浏览器名称:”+navigator.appName+“”; txt+=“浏览器版本:”+navigator.appVersion+“”; txt+=“Cookies已启用:”+navigator.cookieEnabled+“”; txt+=“平台:“+navigator.Platform+””; txt+=“用户代理标题:“+navigator.us

**我如何在我的网站上写下由c#设计的java代码


txt=“浏览器代码名:”+navigator.appCodeName+“

”; txt+=“浏览器名称:”+navigator.appName+“

”; txt+=“浏览器版本:”+navigator.appVersion+“

”; txt+=“Cookies已启用:”+navigator.cookieEnabled+“

”; txt+=“平台:“+navigator.Platform+”

”; txt+=“用户代理标题:“+navigator.userAgent+”

”; document.getElementById(“示例”).innerHTML=txt;**
你可以像网站不是用C#制作的一样,用同样的方式来做这件事。将javascript代码放在页面源代码的脚本标记中(而不是代码隐藏)


//把你的剧本放在这里
...
编辑:

要获取控件的客户端ID(如果它是C#WebControl,而不是HTML表单元素),可以使用
txt.ClientID

在javascript中,这将创建:

myJsTextBox=document.getElementById(“”)

猜测(如果是错误的,请扩展您的问题以说明问题的实质):

“txt”变量是codebehind中的一个C#变量,您希望在javascript中使用该值

1) 将HTML/javascript代码更改为

document.getElementById("example").innerHTML=<%= GetTxt() %>;
document.getElementById(“示例”).innerHTML=;
2) 在codebehind中添加一个
getText()
方法,该方法传递txt变量的内容,包括周围的引号,并确保生成的javascript有效(转义的内部引号等)

在呈现页面服务器端时使用此方法。该方法的结果作为javascript行的一部分发送

<html>
<head>
    <script type="text/javascript">
        // put your script here
    </script>
</head>
...
</html>
document.getElementById("example").innerHTML=<%= GetTxt() %>;