I am currently working on my final thesis.I have a small problem.I need to pass a HTML block which is a string block to a javascript function.I have to do this from code behind.I have tried it so much I doesnt seem as it is going to work.Here is the code in code-behind:

```
string htmlFlightDetailsJavaScript ;

```

In the string there are few div and tables which have class propeties. something like div class="bla"

```
ClientScriptManager cs = Page.ClientScript;
StringBuilder csText = new StringBuilder();
csText.Append("fill("+htmlFlightDetailsJavaScript+");");
cs.RegisterStartupScript(this.GetType(), "alert", csText.ToString(), true);

```

Here is my javascript function:

```
function fill(b) 
{
   alert(b);
}

```

Note that my javascript function is on the ~.aspx.

I have tried to pass the string without classes which are in the div and the table in string and it is working.But when I try to pass it with the classes,it does not work.Can anyone help me?

Thank you very much
['https://Stackoverflow.com/questions/5808172', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/727788/']
Use the RegisterClientScriptBlock() method and make sure to escape your quotes in your HTML.

"<div class=\"blah\">"
I guess you can accomplish much faster if you use an ajax call and a partial control (user control) or write the content yourself.

1) The user control will render your html data.
2) The page code behind will receive the ajax call and call the method thal will render the partial control or write.
3) The method will write on Response.Output stream and end the Response (Response.End())
4) The javascript will handle the response and show the result.

(using jQuery)

```
// main.js

jQuery.ajax({
    type: 'POST',
    data: { isajax: true, ajaxcall: 'MyMethod' },
    dataType: 'html',
    success: function (data, textStatus, jqXHR) {
        alert(data);
    }
});

// CodeBehind
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.HttpMethod == "POST" && Request["isajax"] == "true")
    {
        this.AjaxCall(Request);
    }
}

private void AjaxCall(HttpRequest request)
{
    switch (request["ajaxcall"])
    {
        case "MyMethod": this.MyMethod(request); break;
        default: break;
    }
}

private void MyMethod(HttpRequest request)
{
    Response.ContentType = "text/html";

    Response.Write("YOUR CONTENT GOES HERE.");
    // Or, render a User Control

    Response.End();
}

```

P.S.: You can use a Generic Handler if you wish to. Just add the url option to jQuery ajax method.

Let me know if it helps.