stringbuilder problem

Last post 05-09-2008 9:41 AM by NC01. 5 replies.

Sort Posts:

  • stringbuilder problem

    05-06-2008, 7:55 PM

    Hi, I have a string builder which does the following,

     StringBuilder sb = new StringBuilder();

     sb.AppendLine("-Agency name cannot be empty");

    sb.AppendLine("-Phone cannot be empty"); 

    now i also have this,

    ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(string), "script", "alert('" + sb.ToString()+ "');", true); 

     but i have the error, "unterminated string constant stringbuilder"

    any idea what to do? to get rid of this..

     

    Thanks,
     

  • Re: stringbuilder problem

    05-06-2008, 8:03 PM
    Answer
    • Loading...
    • mbanavige
    • Joined on 11-06-2003, 1:29 PM
    • New England, USA
    • Posts 6,852
    • Moderator
      TrustedFriends-MVPs

    since the string you're building will become a piece of javascript, you would want to avoid AppendLine which appends a crlf and use \n wherever you want a newline

    sb.Append("-Agency name cannot be empty\n");

    sb.Append("-Phone cannot be empty\n"); 

    Mike Banavige
    ~~~~~~~~~~~~
    Dont forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
  • Re: stringbuilder problem

    05-08-2008, 11:59 AM

    nope..i couldn't get it work...

    i think i forgot to mention the textbox and the button is wrapped inside an ajax update panel too..

    help pls? 

  • Re: stringbuilder problem

    05-08-2008, 12:40 PM
    Answer
    • Loading...
    • NC01
    • Joined on 08-26-2005, 7:33 PM
    • Posts 6,867
    • TrustedFriends-MVPs

    As Mike posted the only time that I get an Unterminated string constant error is when I use sb.AppendLine. If you use sb.Append("-Agency name cannot be empty\n") you will have the same problem. This, however, worked with no problems.
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append("-Agency name cannot be empty\\n");
    sb.Append("-Phone cannot be empty\\n");

    ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(string), "script", "alert('" + sb.ToString()+ "');", true);

    NC...

  • Re: stringbuilder problem

    05-08-2008, 4:40 PM

     That worked..Thanks to both mike and NC...

     :)
     

  • Re: stringbuilder problem

    05-09-2008, 9:41 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 7:33 PM
    • Posts 6,867
    • TrustedFriends-MVPs

    Glad you finally got it fixed!

    NC...

     

Page 1 of 1 (6 items)