I bet! You might have came across this error, at least once in your development, while playing with master pages.
Error creating control
Response is not available in this context
But still, the page will render during runtime, without any issues.
I came across this error last night. Though, I have been seeing this error for a last few years, I clearly don’t have an idea what’s exactly the reason for this design-break. But, now I know, Why it’s behaving so!
Here goes the reason. All my content pages are inheriting a base class. One of the functionality of base class is to check for authorized users in the OnInit event of the webpage.
Now, what was the reason for the error?
Read the error message carefully – “Response is not available in this context”. Say it again, “Response is ….”. Now, check the above code again.
Inside the if statement, I’ve a Response.Redirect. In designer mode, Response is simply null because I haven’t executed my webpage yet and does not have any value.
Workaround? Yes, simply include a null check!
Now, rebuilt your website and check the design-mode.
Viola! That’s all.
Please note, objects like Session will also cause this problem because their value won’t be available in design-mode (read more).
Hope this helped.
It was a surprise when I suddenly see a YSOD in a newly added webpage.
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "AjaxControlToolkit.Properties.Resources.NET4.resources" was correctly embedded or linked into assembly "AjaxControlToolkit" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Ah! After some careful look at the code, there it is. I forgot to add the ToolkitScriptManager.
Now that was a silly and careless mistake.
Last day, one of my colleague approached me with a strange problem. She had a button whose client-side click opens a popup window. At the time of opening, she’s passing a sequence number as querystring value, which contains a plus(+) sign.
But, upon receiving the querystring value, the plus(+) sign was automatically converted to a white-space.
As a quick fix, she thought about replacing the whitespace with plus(+) sign, while reading the querystring. But, that’s not a solution at all. Because, if the sequence contains both plus sign and whitespace, we cannot distinguish them and the above method fails.
Another option was to encode the complete url before calling window.open and decode it at the server-side. But, that will not solve the problem either.
However, the solution is pretty straight forward and simple. Encode the querystring value using encodeURIComponent() method. Please note, encode querystring value ONLY.
Yup! That’s the solution.