call a c# function in javascript

Possible Duplicate:
Call c# function in javascript

I have ac# function containing an if statement (if (condition) test=true else test= false )), Can anyone tell me how to call that function in javascript and use the result of that test variable to do an if statement.

The c# file I am referencing is the code behind (.aspx.cs) to an .aspx page. Is there not a way I can call the following function from this .aspx page.

public void write(bool complete)     
{          
System.IO.StreamWriter writer = new System.IO.StreamWriter(Server.MapPath("~file.txt"), true);          
if (complete == true)         
{             
writer.WriteLine("completed");         
}         
else         
{             
writer.WriteLine("FAILED");         
}         
writer.Flush();         
writer.Close();         
writer.Dispose();     
} 

it sounds like in your situation, No, the javascript is running in the browser, and the C# code is running on the server.

You could postback to the server to get it run the C# code if you wanted.


You are repeating the questions. You have got few answers for your previous same question as well Call c# function in javascript

Without postback you cant access the code in .cs file. If you want partial Post back try using AJAX

链接地址: http://www.djcxy.com/p/30996.html

上一篇: 超链接在checkboxfield detailsview中

下一篇: 在JavaScript中调用ac#函数