简体   繁体   English

在.JS文件中使用C#代码?

[英]Using C# Code in a .JS file?

Just curious if it is possible, I have a C# WFA Project, and I want to be able to import some .js files I have laying around for a multi-purpose tool I am making, I have the .js file in my project, is there any possible way where I can write like form1.textBox1.Text in the js file, like add a reference from the C# file(s) to it or something? 只是想知道是否有可能,我有一个C#WFA项目,并且我希望能够导入一些我正在制作的用于多功能工具的.js文件,我的项目中有.js文件,有什么可能的方式可以在js文件中编写像form1.textBox1.Text一样的内容,例如从C#文件中添加对它的引用? Just asking if it's possible. 只是问是否有可能。

You can get the value of the asp controls using JQuery as follows 您可以使用JQuery来获取asp控件的值,如下所示

Your .ascx/.aspx 您的.ascx/.aspx

<div id='form_holder'>
  <asp:TextBox id='txtEmail' runat='server' />
  <asp:TextBox id='txtPassword' runat='server' />
</div>

Your .js 您的.js

function foo() {
    var txts = $("#form_holder").find("input[type=text]");
    var email = txts[0].value;
    var passwd = txts[1].value;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM