2

i am trying to alert string variable value using java script from code bhind my code is,

ClientScript.RegisterStartupScript(typeof(Page), "ScriptDescription", "<script type=\"text/javascript\"> alert('Error: Consultant '" + ConsZeroProj + "' projects do not exsist. Please select consultant having projects.');</script>");

ConsZeroProj is string variable having value if i remove this variable it display alert and when i append it . It do not show any alert what is the reason ?

hopes for your suggestion thanks

8
  • Are you sure that ConsZeroProj has some value in it? Commented Sep 10, 2013 at 9:59
  • 1
    Does by any chance ConsZeroProj contain ' character? Probably you can also find an error in your browser javaScript console. Commented Sep 10, 2013 at 10:00
  • 1
    what is the value of ConsZeroProj ? may be it should be encoded? Commented Sep 10, 2013 at 10:00
  • it contains "PB Americas, Inc." value Commented Sep 10, 2013 at 10:08
  • i also tried by changing variable value to "STV" until then it is behaving same :( Commented Sep 10, 2013 at 10:10

1 Answer 1

4

Remove single quotes wrapping the variable ConsZeroProj. Use the following code.

ClientScript.RegisterStartupScript(typeof(Page), "ScriptDescription", "<script type=\"text/javascript\"> alert('Error: Consultant " + ConsZeroProj + " projects do not exsist. Please select consultant having projects.');</script>");

It is working, tested at my end.

Sign up to request clarification or add additional context in comments.

1 Comment

my reputation do not allow me to up vote your answer when i will be able i will vote it up !

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.