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/']
You can use the [ClientScriptManager.RegisterStartupScript](http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx) method.
I'd take a step back and examine whether the entire HTML block is really so dynamic that it needs to be passed into the function as a parameter. 

The easier way would be to have the HTML element emitted as part of the page, then augment that from your function. ie. show or hide it.

If your scenario still requires you to pass the HTML as a parameter, you'll need to [HTML encode](http://msdn.microsoft.com/en-us/library/w3te6wfz.aspx) the entire string on the server side, and then [Unencode](https://stackoverflow.com/questions/1219860/javascript-jquery-html-encoding) in JS.