使用Page.ClientScript将C#值传递给JavaScript

使用Page.ClientScript将C#值传递给JavaScript,c#,javascript,C#,Javascript,我在C#中有一个可个性化的值 我试图使用Page.ClientScript将变量'TimeToStand'传递给JavaScript函数 protected void Page_Load(object sender, EventArgs e) { Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript>

我在C#中有一个可个性化的值

我试图使用Page.ClientScript将变量'TimeToStand'传递给JavaScript函数

protected void Page_Load(object sender, EventArgs e)
        {
          Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript> newfunc(TimeToStand); </script>");            
        }
如果我遗漏了什么,请告诉我。
谢谢

您将其作为字符串的一部分,因此您得到的不是变量的值
TimeToStand
,而是变量名称的字符串表示形式,请尝试以下操作:

Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript> newfunc(" + TimeToStand + "); </script>");  
Page.ClientScript.RegisterStartupScript(this.GetType(),“PopupScript”,“newfunc(“+TimeToStand+”);”;
试试这个

Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript> newfunc("+TimeToStand+"); </script>"); 
Page.ClientScript.RegisterStartupScript(this.GetType(),“PopupScript”,“newfunc(“+TimeToStand+”);”;

你比我早30秒回答。祝我下次好运。哦,谢谢你,朋友:)谢谢@SidM和PSL。我不能+1,因为我没有足够的声誉here@Sagarika:你能在PSL答案上打勾吗?因为他先回答了正确的答案。
Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript> newfunc(" + TimeToStand + "); </script>");  
Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script type=text/javascript> newfunc("+TimeToStand+"); </script>");