我必须使用c#在asp.net的codebehind文件中访问我的javascript中的时间 [英] i have to access time in my javascript at codebehind file in asp.net using c#

查看:39
本文介绍了我必须使用c#在asp.net的codebehind文件中访问我的javascript中的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="application/javascript">
    var myCountdown2 = new Countdown({
        time: 3600,
        width: 40,
        height: 22,
        rangeHi: "minute"   // 
    });

</script>

推荐答案





您不能将javascript变量直接指定给后面的代码。如果没有向服务器发送和发送HTTP请求,您就无法在客户端和服务器端之间进行交互。

但你可以这样做:



1.)在客户端创建一个隐藏的字段变量:

Hi,

You cannot assign as javascript variable directly to code behind. You cannot interact between client side and server side without sending and HTTP request to the server.
But you can do it like this:

1.) Create a hidden field variable in the client side:
<asp:HiddenField id="hdnField" runat="server" />



2.)在javascript中分配隐藏变量的值


2.) In javascript assign a value to the hidden variable

var hdnfield = document.getElementById('hdnField');
hdnfield.value = 3600;



3.)在代码中获取隐藏的字段变量背后:


3.)Get the hidden field variable in the code behind:

object time = hdnField.Value;





希望这有帮助!! :):)



Hope this helps !! :) :)


这篇关于我必须使用c#在asp.net的codebehind文件中访问我的javascript中的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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