.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Really Long JSON String wraps to multiple lines in source, creates unterminated String Literal error

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :ASP.Net

I have an app that writes a JSON object to a string and registers a script block onto the page that client-side javascript then uses to build interface components.  I found that the javascript is working fine when the data set is small, but on large datasets, when I view the source, the JSON object string takes up a few lines because it is so long.  I didn't think anything of it until I started manually trying to recreate the "Unterminated String Literal Error", only to find that the error goes away when I format the JSON string to be a little more "readable".  What I discovered is that this does away with the automatic new line wrap, making the error go away. 

Make Sense?  Is there anything I can do about this?

View Complete Post

More Related Resource Links

unterminated string literal issue in asp.net onclick


<img width="15" height="15" border="0" onclick="_s.my.letters.action.fillDataForMenu(this, {id:'26308409', title: 'hi''})" src="http://media.newjobs.com/mm/redux/cover-letter/flyoutPoint.png" alt="action">

this is code generated for the image button for my which looks like

<img height="15" border="0" width="15" alt="action" src="http://media.newjobs.com/mm/redux/cover-letter/flyoutPoint.png" onclick="_s.my.letters.action.fillDataForMenu(this, {id:'<%# ((SimpleLetter)Container.DataItem).ID %>', title: '<%# ((SimpleLetter)Container.DataItem).EncodedTitle %>'})"/>

but this code is giving the Error as "unterminated string literal" in javascript if i include the single quote in the Title Text.....(')

remaining cases its working good

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

error in MVC2 on empty string form fields which are required: "This property cannot be set to a null

In model I have:[DisplayName("ISBN")] [Required(ErrorMessage = "ISBN is required.")] [StringLength(50, ErrorMessage = "ISBN book must have max {1} chars.")] [DisplayFormat(ConvertEmptyStringToNull = false)] public string isbn { get; set; }But when I submit form with empty field ISBN I have an error - ConstraintException: This property cannot be set to a null value.I have find that other people have the same problem and they say that debbugger in VS2010 works wrong - yes ?http://p2p.wrox.com/book-professional-asp-net-mvc-2/79788-constraintexception-unhandled-user-code.html#post259245http://efreedom.com/Question/1-3129080/Server-Side-Validation-REQUIRED-String-Property-MVC2-Entity-Framework-Workhttp://mvcmusicstore.codeplex.com/workitem/6604

XML Web Services: Invalid URI: The Uri string is too long.

error  Invalid URI: The Uri string is too long. (UriFormatException was unhandled by user code)

Duplicate URLs in Source Parameter of Query String for All SharePoint Lists

After performing a database attach method of upgrading our existing web application from MOSS 2007 to SharePoint Server 2010, all of our lists that migrated now exhibit an interesting but undesirable behavior.  The DispForm.aspx and EditForm.aspx pages that get loaded are given the Source parameter of the query string but instead of the URL being a single entry like: Source=http://sharepointsite.domain.com/Pages/Default.aspx It winds up putting the URL twice like this: Source=http://sharepointsite.domain.com/Pages/Default.aspx,http://sharepointsite.domain.com/Pages/Default.aspx Naturally this makes processing of the form -- either by choosing OK or Cancel buttons -- result in an HTTP 404 error.  The question we're left with is how in the world did the Source parameter get set that way to begin with.   It wasn't that way in 2007. We had thought that perhaps there was something that didn't migrate over correctly for the existing lists, so I tried creating a new list and then added a new item to the list.  So far so good.  Then attempted to Edit Properties or Edit Item or even View Item, etc. -- essentially triggering the load of the EditForm.aspx and DispForm.aspx  -- and we received the 404 again.  At this point we're not sure what's going on or how to fix it.  We've performed the migration three times so far with t

Failed to set image source with string resource

User can set image source property like this: <Image Source="pack://application:,,,/MyResource;component/Images/1.ico" /> I think the source string is a little bit longer, so I want to make it as string resource: <sys:String x:Key="StringSourceKey">pack://application:,,,/MyResource;component/Images/1.ico</sys:String> After define the string resource, I use it to set image source, like this: <Image Source="{StaticResource StringSourceKey}" /> But, this time, it failed. It doesn't work. I think it is a contert error. Anybody know what's wrong?  Or any method to make the resource uri path shorter? Thanks.

WebSecurity covert string to int error?

Server Error in '/dev' Application. Cannot convert type 'string' to 'int' Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot convert type 'string' to 'int' Source Error: Line 12: login_password = Request.Form["login_password"]; Line 13: string login_username = Request.Form["login_username"]; Line 14: if(WebSecurity.Login(login_username, login_password)){ Line 15: Response.Redirect("~/"); Line 16: } Source File: c:\WWW\cisatools.com\apps\csg\dev\login.cshtml Line: 14 Stack Trace: [RuntimeBinderException: Cannot convert type 'string' to 'int'] CallSite.Target(Closure , CallSite , Object ) +216 System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site, T0 arg0) +344 Microsoft.WebPages.SimpleMembershipProvider.GetUserId(Database db, String userTableName, String userNameColumn, String userIdColumn, String userName) +1199 Microsoft.WebPages.SimpleMembershipProvider.VerifyUserNameHasConfirmedAccount(Database db, String username, Boolean throwException) +51 Microsoft.WebPages.SimpleMembershipProvider.Vali

error: cannot implicitly convert type 'string' to 'int?'

Hey guys,I am trying yo build the following class for which i get an error on the line this.id = e.id as cannot implicitly convert type 'string' to 'int?'. can anybody help me with it??many many Thanks,Chetan.using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Data.Linq;using System.Text;using System.Runtime.Serialization;using HsInternet.Data.DAL;namespace HsInternet.Data.BLL{    public class Baby    {        public int id { get; set; }        public string name { get; set; }        public string parents { get; set; }        public int gender { get; set; }        public string weight { get; set; }        public string length { get; set; }        public DateTime date { get; set; }        public DateTime time { get; set; }        public string image { get; set; }        public string ipa { get; set; }        public string ipb { get; set; }        public Baby()  &

Can't pass string to javascript function(unterminated string)

Hello,I have a problem. I can't pass string like this  ": Mar 15 2004 12:00AM  Refnr: 20040315!m>N0"to javascript function because I have symbols like these >, <, % ?tc.Situation:I have a Grid and I have column with DataItemTemplate,Within my dataitemtemplate I have <a href="javascript:void(0);"  onclick="ShowAccountStatementNote(document.getElementById('<%= lblHiddenNoteText.ClientID %>').value);" >                                                          Bekijken...                                                      </a><a href="javascript:void(0);"  onclick="ShowNote('<%# EncodeStringToHTML(Eval("Note")) %>');" > Notes </a>ShowNote function just show popup with text = NoteEncodeStringToHTML do Server.HtmlEncode(); But It doesn't help because even if we change text on server .... e.g. "dfdf%" convert to "dfdf&#37;"  anyway on client it becomes again "dfdf%" and problem still exists.On clien

Simple error connection string null reference

 It is failing on SqlHelper.ExecuteNonQuery(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString     public static string GetAboutMeName(string sUserID, string connectionString)        {             SqlParameter[] parameters = new SqlParameter[2];                      parameters[0] = new SqlParameter("@sUserID", SqlDbType.VarChar, 50);            parameters[0].Value = sUserID;             parameters[1] = new SqlParameter("@sResult", SqlDbType.NVarChar, 1000);            parameters[1].Direction = ParameterDirection.Output;             // Execute the stored procedure            SqlHelper.ExecuteNonQuery(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString, CommandType.StoredProcedure, "sprGetAboutMeName", parameters);         &n

statement with SQL_C_WCHAR returns 22001 string data, right truncation error

I am trying to execute the following code  value = L"Test13Digit++"; SQLPrepare(stmt, L"delete Entries where [type] = ?", SQL_NTS); SQLBindParameter(stmt, paramNumber, SQL_PARAM_INPUT, SQL_C_WCHAR, SQL_WVARCHAR, 100, 0, (SQLPOINTER) value.c_str(), 0, &strLen); SQLExecute(stmt); the table entries is as follows: Entries ([type] nvarchar(100), [key] nvarchar(100), [version] bigint, [data] varbinary(8000), CONSTRAINT PK_Entries PRIMARY KEY([type], [key]))   I keep getting the 22001 - string data, right truncation error. I have tried all different versions of WCHAR types but does not seem to help.

Obtain url query string during Json request

So I'm writing an MVC application, and have a JsonResult post back to obtain some item information for scanned items on a warehouse application I am writing. I'm trying to obtain a URL query string value though, and cannot seem to obtain one via the normal 'Request.QueryString['variable']' way... Is there a way to do this? I also thought about just passing the parameter into my post, but I already have a single value on my jquery post, and I am unsure if I can tack on more values to this. Thanks for your help.

deserialize json string using javascript serializer problem



A json string was sent from client side to asmx web service.

Here json string is as below

"Name":"Ablation of Aflutter","BillingCode":"93651","ServiceCode":"1062","Value":1},
"Name":"Ablation of Atrial tachy","BillingCode":"93651","ServiceCode":"1062","Value":1},
"Name":"Ablation of AVN for CHB w/ or w/o temp pacer","BillingCode":"93650","ServiceCode":"1061","Value":1},
"Name":"Ablation of VT","BillingCode":"93652","ServiceCode":"1063","Value&q

How to build long query string



I know that it is basic questions, but I am stuck here.

I have TableOne have fields: USERNAME, PID, GID, TID, SID, NEWSID. I need to write query string to check if those value is already in the table. If not, insert those value to the table.

string AddUserName = UsernameToken(GetUsername);
string InsertString = "insert into TableOne(USERNAME, PID, GID, TID, SID, NEWSID) values (?, ?, ?, ?, ?, ? )" + "  WHERE NOT " + " ( "  [USERNAME] = '" + AddUserName + "' + " PID = '" + DropDownBoxPID.Text.Trim() +
 '" + " AND " + " GID = '" + DropDownBoxGID.Text.Trim()  +
 '"  + " AND " + "  TID = '" + DropDownBoxtid.Text.Trim()  +  
 '" + " AND " + " SID = '" + Textboxsid.Text.Trim() +  
 '" + " AND " + " NEWSID = '" + DropDownssid.Text.Trim() +
 '" + ")" ;

However, I got the many errors:

Error    1    Too many characters in character literal  

Error    3    Newline in constant   

Is any way to debug this? As always, your help is highly a

Runtime error in string builder which was declared static


My code to insert data is as follows it works for the first time if i tried to insert data for the second time i am getting the error

My complete code




using System . Collections . Generic ;
using System . Text ;
using System . IO ;
namespace ACHDAL
public class EntryDetail

int [] debits ={ 25 , 26 , 27 , 28 , 29 , 35 , 36 , 37 ,

Runtime error in string builder which was declared static


My code to insert data is as follows it works for the first time if i tried to insert data for the second time i am getting the error

object reference not set to an object


SQL error: Conversion failed when converting date and/or time from character string.

I hope someone can advise on the issue I'm having.

This SQL worked beautiful until I added in @startdt and @enddt and this section >> AND [Selldate] BETWEEN ' + @startdt + ' AND ' + @enddt + '

By adding in this condition, I now get the following error:

Msg 241, Level 16, State 1, Line 8
Conversion failed when converting date and/or time from character string.

I have tried changed variables to type = date and various iterations of date formatting, casting with no success. The date in the table is clean as a whistle.

(The CONVERT function is being used in setup for a PIVOT SQL which needs  VARCHAR for column headers)

Thanks in advance for your help, 

declare @itemID varchar(20)
declare @startdt varchar(12)
declare @enddt varchar(12)
set @itemID = ''
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend