如何从javascript文本获取价值到c#variale [英] how to get value from javascript text to c# variale

查看:72
本文介绍了如何从javascript文本获取价值到c#variale的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用javascript中的提示从用户那里获取值.单击确定后,用户在文本框中输入的值应存储在c#变量中. 这是我的代码.,

i used prompt in javascript to get value from user.,what the value entered by user in textbox after click OK it should store in c# variable.,
here i my code.,

推荐答案


采取一个隐藏的字段,并将在javascript提示中输入的值设置为该字段.使用此代码,您可以使用C#编码获取输入的文本.如果要刷新页面,然后在从用户输入值之后在那里刷新,则可以使用 __doPostBack [
Hi,
Take a hidden field and set the value entered in javascript prompt to it. Using this you can get the entered text using your C# coding. If you want to refresh the page then and there after entering the value from user then you can use __doPostBack[^] function of javascript.

Try this:
<html>
<body>
<input type="submit"  önclientclick="myFunction()" value="Click Me"/>
<asp:Label  runat="server" id="lbl"/>

<script type="text/javascript">
function myFunction()
{
    var x;    
    var name=prompt("Please enter your name","Test Name");    
    if (name!=null)
    {
         document.getElementById("lbl").innerHTML=name;
         //You can use __doPostBack here to refresh the page if required.
    }
}
</script>
</body>
</html>




--Amit




--Amit



这篇关于如何从javascript文本获取价值到c#variale的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆