"This is a regular string"
@"This is a string literal
This is the second line of the string literal, it includes a carriage return/linefeed."
@"This is a string literal
with ""Double Quotes!"". Isn't it cool?"
The third example produces a string literal with the words "Double Quotes!" in double quotes, exactly as you'd expect. Chalk one up for obvious features whose solution isn't as obvious as you might think.
[ add comment ] | permalink | related link |




( 2.9 / 42 )So one of the business user decides that he needs to be able to press the enter key on a webform to submit. Specifically, during the login process. This kind of stuff is supposed to work by default, but when you're building a complex web app, sometimes you need more fine-grained control over the behavior of the enter key.
Here's a class I've created that allows you to specify the behavior of the enter key on all controls in your form.
EDIT: I've also added a fix for a case where you want to click a link rather than a button.
public class EnterKeyHandler
{
/// <summary>
/// When the user presses the "enter" key while control_to_watch has focus, call click on button_to_submit
/// </summary>
/// <param name="control_to_watch"></param>
/// <param name="button_to_submit"></param>
public static void ClickButtonOnEnter(WebControl control_to_watch, WebControl button_to_submit)
{
string js = @"
if (event.which || event.keyCode) {
if ((event.which == 13) || (event.keyCode == 13)) {
if ($get('@id@').href) {
eval($get('@id@').href);
} else {
$get('@id@').click();
}
return false;
}
} else {
return true;
}";
control_to_watch.Attributes.Add("onkeydown", js.Replace("@id@", button_to_submit.ClientID));
}
/// <summary>
/// When the user presses the "enter" key while control_to_watch has focus, set focus to next_focus
/// </summary>
/// <param name="control_to_watch"></param>
/// <param name="button_to_submit"></param>
public static void NextControlOnEnter(WebControl control_to_watch, WebControl next_focus)
{
string js = @"
if (event.which || event.keyCode) {
if ((event.which == 13) || (event.keyCode == 13)) {
$get('@id@').focus();
return false;
}
} else {
return true;
}";
control_to_watch.Attributes.Add("onkeydown", js.Replace("@id@", next_focus.ClientID));
}
[ add comment ] | permalink | related link |




( 2.7 / 74 )This is something I don't like, but I'll explain how to do it anyway.
Some clients want websites where people can't select your text and can't right click on your images.
I think this is silly; it doesn't really protect your website. For example, if anyone wants to copy your content, they can still take screenshots or view your HTML source. Screen scrapers can still save the contents of your web browser to disk.
However, recently I was building an app that involves lots of mouse movement, and I noticed that once in a while you'd select text if your mouse was moving when you clicked. You'd get a huge block of white-on-blue text in the middle of a page makes it seem like something is broken.
I researched a little bit and found a way to disable this, so I present this to you here. First, edit the body tag of your HTML document with these javascript handlers:
<body oncontextmenu="return false;" ondragstart="return false;" onselectstart="return preventselect();" onmousedown="if (typeof event.preventDefault != 'undefined') {
event.preventDefault();
}"
Next, define this function somewhere in your HTML page:
function preventselect()
{
var el = event.srcElement;
return (el.type == 'text');
}
This "preventselect" function allows the user to still select text if it's within an input box. You might want to modify this function to allow text selection in whatever cases you prefer.
[ add comment ] | permalink | related link |




( 3.1 / 52 )I recently started to see this error message in my Visual Studio .NET 2008 project.
"The following module was built either with optimizations enabled or without debug information"
This didn't make sense, because I was debugging and doing just fine. I found some various bits of advice online for this problem:
1) Clear the "read-only" flag from your "bin" directory
2) Delete your project references and re-add them in the correct order.
3) Rebuild your solution
Sounds easy? The real problem was that I was adding projects in the wrong order that had cross dependencies. For example, I have a solution W which includes libraries A, B, and C. Library A includes library C. What I needed to do was to delete all the references and add them from the ground up. That meant I did this:
1) Right click on my solution W and select "Property Pages".
2) In the references page, delete all of my project references.
3) Add a reference to the project for library C.
4) Add a reference to the project for library B.
5) Add a reference to the project for library A (which needs C, which finds it already exists, which then doesn't need to add a faked reference).
6) Recompile.
Wild!
[ add comment ] | permalink | related link |




( 2.9 / 69 )So recently I started getting the error "Sys.Application is null or not an object" when I debug my .NET website application. A javascript error? Since when do applications die on a javascript error?
I found a few references on the web to similar problems. But the best solution seemed to be to create a blank website project and line-by-line compare the web.config file with my broken one. The error was in fact in the document's root tag. Here was the error:
Broken File:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
Corrected File:
<configuration>
Apparently it had something to do with a long lasting project that got upgraded from 2.0 to 3.5.
[ add comment ] | permalink | related link |




( 2.9 / 82 )Next

Calendar



