Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Does any one knows a method to get JavaScript Variable value to a C# variable?
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;           
{
   string serverName;
   string javascript = 
             "<script language=JavaScript>\n" +
             "var server = prompt('Enter SQL server Ip or Name?', 'Testserver');\n" +
             "if (favorite) alert('Successfully configured: ' +  favorite);\n" +
             "else alert('You pressed Cancel or no value was entered!');\n" +
             "</script>";
   //string h = serverName;
   System.Web.HttpContext.Current.Response.Write(javascript);

I want to get this " server" variable value to a C# variable!(String serverName)

Thanks in advance!!!
Posted
Updated 30-Mar-12 15:08pm
v7
Comments
Bojjaiah 30-Mar-12 13:01pm    
edit to add pre tag

Start here[^]. Not sure why you couldn't have Googled that for yourself: took a few seconds to find it.
 
Share this answer
 
Comments
[no name] 30-Mar-12 11:44am    
That link he gave you does exactly that.
Shahin Khorshidnia 30-Mar-12 15:44pm    
My +5
yes that's it!
 
Share this answer
 
Comments
Hesha 30-Mar-12 20:48pm    
But the problem was this method did not worked when i used it under serverside to run the javascript( in my C# class)
Hesha 1-Apr-12 0:29am    
i solve out the problem.Thanks for support Mark , Wes , shahin... i did little modification after reading your suggested pages.. Thanks guys for Support!!!
Bojjaiah 2-Apr-12 1:14am    
Welcome :)

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