Click here to Skip to main content
16,022,798 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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 :

JavaScript
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# code is:


C#
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 data is further passed to custom control to display local time modified as per client machine time offset

settings
Posted
Updated 8-Mar-12 22:59pm
v3

1 solution

You can call JavaScript from C# code. Here is the sample:

JavaScript
<script>
function hi(var someVar)
{
   document.write("hello " + someVar);
}
</script>


C# code behind looks like:

C#
string passName = "username";
Page.RegisterStartupScript("myScript", "<script language="JavaScript">hi('" + passName + "');</script>");
 
Share this answer
 
Comments
ninad from cybermediasoft 9-Mar-12 5:11am    
can u elaborate this code in given example..with code where local time returned by script can be taken to array.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900