ASP.NET - Tips - Could not open in Design view. Quote Values differently inside a '<%... "value" ...%>' block.
VS.NET - Bug Workaround
Synopsis:
VS.NET has a bug with nested double quotation marks(") inside inline asp.net code. If this code exists in a webform (HTML not codebehind), the webform will work fine but when you attempt to go into the design mode of VS Designer an error will appear and the graphical designer will not launch. The solution is to simply replace the outer quotation marks with single quotation marks(').
Example:
<body onload="someJSFunction(<% response.write(session("someVar")) %>)" >
The quotes surrounding the onload javascript function call can be replaced with single quotes and will also allow the vs.net design environment to start up without the "Could not open in Design view" error.
<body onload='someJSFunction(<% response.write(session("someVar")) %>)' >
IMPORTANT! Be aware that any single quotes that were previously used between the outer double quotation marks should now be switched to double quotation marks. The same goes for any text written back from a response.write.
Example:
This code will not work:
<body onload='someJSFunction(<% response.write("'" & session("someVar") & "'") %>)'>
This code will work:
<body onload='someJSFunction(<% response.write("""" & session("someVar") & """") %>)' >
The quotes surrounding the onload javascript function call can be replaced with single quotes and will also allow the vs.net design environment to start up without the "Could not open in Design view" error.
<body onload='someJSFunction(<% response.write(session("someVar")) %>)' >
IMPORTANT! Be aware that any single quotes that were previously used between the outer double quotation marks should now be switched to double quotation marks. The same goes for any text written back from a response.write.
Example:
This code will not work:
<body onload='someJSFunction(<% response.write("'" & session("someVar") & "'") %>)'>
This code will work:
<body onload='someJSFunction(<% response.write("""" & session("someVar") & """") %>)' >