1

i'm my code behind of my web application, i have this method associated to the event click

protected void Button1_Click(object sender, EventArgs e)
{

      string pagFinal = "this is a test";

      ClientScript.RegisterClientScriptBlock(this.GetType(), "variable", "<script language=javascript> var direction = <%=pagFinal%> </script>");

}

but when i see the html generated doesn't appear's the javascript why i'm doing wrong. Thanks

1
  • You've embedded server side code in your JS snippet. That Will however be outputted literally Commented May 18, 2011 at 14:52

1 Answer 1

6

You can directly replace the variable value in your code -

ClientScript.RegisterClientScriptBlock(this.GetType(), "variable", "<script language=javascript> var direction = '" + pagFinal + "'; </script>");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.