如何将日期时间对象从aspx.cs传递到.aspx中的javascript函数 [英] how to pass date time object from aspx.cs to javascript funtion which is in .aspx

查看:92
本文介绍了如何将日期时间对象从aspx.cs传递到.aspx中的javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我,使用以下代码调用js函数





I,m using the following code to call js function


AjaxControlToolkit.ToolkitScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "Display(dt);", true); 


where display is my javsript function name and dt is my date time object.


code in js

Function Display(dt)
{
 alert(dt);
}

推荐答案

试试这个



Try this

protected void btnDisplay_Click(object sender, EventArgs e)
        {
            DateTime serverDateTime = DateTime.Now;
            // if you are using AJAX Update panel, use this
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "display", "Display('" + serverDateTime + "');", false);

            // if not using AJAX Update panel
            Page.ClientScript.RegisterStartupScript(this.GetType(), "display", "Display('" + serverDateTime + "');");

        }










<script type="text/javascript">

        function Display(dt)
        {
            alert(dt);
        }
    </script>


这篇关于如何将日期时间对象从aspx.cs传递到.aspx中的javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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