问题描述
你好,
我已经使用c#代码从交换2k7中检索了日期和时间值,并将其存储到arraylist中.但这
时间"值是根据服务器的偏移量设置.但是,在客户端自定义控件I上显示该时间值时
想要使用我编写的JavaScript根据客户端计算机的时间偏移设置"对其进行修改.
有人可以告诉我如何从C#代码中调用脚本并使用脚本在c#代码中返回的偏移"值和
然后再次将其传递给我想要的任何自定义控件.或其他任何我可以做到的方式
javascript是:
Hello ,
I have retrieved the date and time value from exchange 2k7 using c# code and stored it into arraylist. But this
"time" value is as per the offset setting of the server.But while showing that time value on client side custom control I
want to modify it as per the "time offset setting" of client machine using javascript that i have written..
can anybody tell me how to call the script from C# code and use the "offset" value returned by script in c# code and
then again pass it to any custom control i want.. or any other way i can do it
javascript is :
protected string jScript {
get {
string script = "";
script += " <script language=\"JavaScript\">\n\n";
script += " function LocaleTime() {\n";
script += " var dt,strDt;\n";
script += " dt=new Date();\n";
script += " var utc=dt.getTime()-dt.getTimezoneOffset()*60000;\n";
script += " var utc=dt.getTimezoneOffset();\n";
script += " var d=new Date(utc);\n";
script += " return d.toLocaleString();\n";
script += " }\n";
script += " </script>";
return script;
}
}
C#代码为:
c# code is:
ArrayList data = null;
try
{
data = ss.GetStatus(); // now arralist contains info as id,name,check in time so for loop is used to
//access the check in field only
for (int j = 0; j < data.Count; j++)
{
string tempstring = Convert.ToString(data[j]);
string[] temparray = tempstring.Split(';');
temparray[3] =localtime ; // at this place instead of localtime i want to use the value that is
// returned by javascript
}
arraylist数据进一步传递给自定义控件,以显示根据客户端计算机时间偏移量修改的本地时间
settings
arraylist data is further passed to custom control to display local time modified as per client machine time offset
settings
推荐答案
<script>
function hi(var someVar)
{
document.write("hello " + someVar);
}
</script>
后面的C#代码如下:
C# code behind looks like:
string passName = "username";
Page.RegisterStartupScript("myScript", "<script language="JavaScript">hi('" + passName + "');</script>");
这篇关于在C#中访问javascript返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!