Calling JavaScript from C# code.

Asked By 0 points N/A Posted on -

I want to call JavaScript code from C#.

I have used RegisterClientScriptBlock method to do so.

But now the problem is that this method is being called in a loop.

So, it is executed only once.

I want this code to be executed on every iteration.

How can I achieve this?

Answered By 0 points N/A #92812

Calling JavaScript from C# code.


You can pass a reference from the JS to the C# code which it captures and can execute JS script back.

function do_Print() {
function report_back(report){

public void setPage(mshtml.HTMLWindow2Class JSFile) {
            window = JSFile;
public void scriptPrint(){
            window.execScript("report_back('Printing complete!')", "JScript");

It works perfectly and without ASP.NET!

But if you want to use the way that you are already using, then I would suggest you to contact the indexer with script title in page client script block method. In this way, every time the code will be registered with a new name so it will be executed. Otherwise,it executes only once.

Login/Register to Answer

Related Questions