Yes, you've read right. You can debug Javascript with Visual Studio. Here is a blog entry that blew my mind when I've read it: JavaScript Debugging.

Basically, what needs to be done is first go to Internet Explorer Options and disable Disable Script Debugging (Internet Explorer) (No, I didn't mistype, there is a checkbox that needs disabling and it's called Disable...) in the Advanced section. Be careful not to disable the other script debugging box, only the Internet Explorer one. Then, when an error occurs, the system asks you what debugger to use. You can choose Visual Studio 2003 or 2005 from the list (provided you have them installed :) ), trace, put breakpoints, etc.

There is also the javascript debugger keyword, which fires a debugging window at the specific location, so it's like a breakpoint.

Googling the net I've found that there are both free and commercial Javascript debuggers. There is even a free one provided by Microsoft: Script Debugger for Windows. One, unfortunately shareware, product that I saw recommended on the forums is 1st JavaScript Editor.

The only disadvantage to this, that I've seen, is that any javascript error will result in opening the debuggers window, without the ability to check "ignore errors on this page" or anything like that. It could be annoying while browsing. Yet I am surprised that I've heard of this method of Javascript debugging only now.

Update:

If it seems the list of debuggers does not appear anymore (or never did), go to Visual Studio Tools -> Options -> Debugging -> Just-In-Time and check the "Script" checkbox.

If it seems Visual Studio doesn't correctly find the right Javascript line to debug when entering debug mode, start the web site without debugging and then choose Microsoft Script Debugger. It gets the current line right, but has a difficult to use interface (Hint: use the Command Window). Of course, you have to download and install it first :).

CSS Friendly ASP.NET 2.0 Control Adapters is a little project run by Brian Goldfarb and what it does is use the power of the ControlAdapter object to change the way ASP.NET controls get rendered. They use CSS layout to control the way things look and try to remove the old table based format.

While this could be a good thing in some situations, it could be harmful in others like low resources or weird changes in the CSS laws. I let you decide for yourselves. And while the ControlAdapter approach is very elegant, I've used this concept in creating my own controls when needed by overriding ASP.NET classes and using simpler code. Also, these Control Adapters are in Beta 2 stage. Major changes are still in the works.

So don't trust it blindly, but do check it out, as it is a worthy and honorable quest :)

and has 0 comments
http://labs.oreilly.com/code/

The above link is the O'Reilly code searcher. You can find any code that was ever published in O'Reilly books.

update:

also check http://www.koders.com, which is a global search engine for code!

The GridView is nothing more than an oversized DataGrid. The internal concept is completely rewritten, as far as I see, though. For example, Columns are not called columns anymore, they are DataControlField. Well, I stumbled upon one situation where I needed to format the autogenerated columns in a GridView. Normally, you could take the Columns collection and change the DataFormatString property for each column, but autogenerated columns (or AutoGeneratedField) are not part of the Columns collection. More than that, AutoGeneratedFields are nothing more than BoundFields with lots of useless restrictions on it like being a sealed class and throwing errors when trying to change some properties (like DataFormatString).

The first step is getting hold of the autogenerated column. Luckily the GridView control has a virtual method called CreateAutoGeneratedColumn which returns a AutoGeneratedField. So create a control that inherits GridView, override this method, take the generated field in the base method, change DataFormatString. I couldn't find any way to do that except with reflection. I noticed that the value of the DataFormatString property was stored in the ViewState of the AutoGeneratedField, so I used reflection to get to it, then I changed the value.

This is the code:
protected override AutoGeneratedField CreateAutoGeneratedColumn(
AutoGeneratedFieldProperties fieldProperties)
{
AutoGeneratedField field =
base.CreateAutoGeneratedColumn(fieldProperties);
StateBag sb = (StateBag)field.GetType()
.InvokeMember("ViewState",
BindingFlags.GetProperty |
BindingFlags.NonPublic |
BindingFlags.Instance,
null, field, new object[] {});
sb["DataFormatString"] = "{0:N}"; //or the format string you prefer
field.HtmlEncode=false; //see update
return field;
}


Update:
The BoundField object formats values differently depending on html encoding. If the html encoding is enabled, then the value is transformed into a string, then the formatting is applied. That means that number formatting will NOT work when html encoding is true.
That is why I've added the field.HtmlEncode=false; line above. A more secure option would be to make the HtmlEncode property depend on the field.DataType.

Update2:
While this works, I don't recommend doing it like that. I am using it because I have custom user controls that inherit from the GridView and I need to cover the AutoGeneratedColumns=true case. It is much easier to generate your columns yourself from the DataSource using BoundField objects (Or any other DataControlField objects) that you add to the GridView.Columns collection.

You know the annoying feeling when you want to find something on the net and you can't find the proper search keywords? It's like trying to find the Triple X movie rather than porn flicks. It happends a lot when you want to find something that you know is named in some way, but a new buzz word is emerging and you either don't find everything you need or you find a lot of unrelated stuff. Like trying to find people talking about computer programming, but you end up with all these TV programming sites. Now try to find how to turn your PC into a TV by programming :).

Anyway, searching on programming led me to wonder about the difference between programming and software development in describing my own job. As previously mentioned, there are other sorts of programming and development except computer ones and to top it all, people mean different things when using these concepts in the software context. Wikipedia, for example, takes "programming" and gives me the page for "computer programming". It then takes software development and takes me to software engineering (which in my mind are different things).

How does google see this? Let's search:
TermPage count
Software development175.000.000
Programming858.000.000
Computer programming19.700.000
Software engineering80.700.000
 
Software developer27.400.000
Programmer156.000.000
Computer programmer4.270.000
Software engineer22.500.000
Developer1.030.000.000

So it seems that there is a lot more programming and programmers than software development or software developers, but add "computer" in front and there is less. But that's because no one bothers to say "computer" in those cases.

And there is more. While software development/engineering start to go towards "designing programs", computer programming goes towards "typing code". I believe that is happening because in large software companies there are a lot of people writing code, but very few that actually have a say on how the program is to behave or what technology to use. I am watching Microsoft presentations and they are ridiculing the "old school" programmers that type their code while the new breed of software developers point, click, drag, drop and everything works in a few minutes. People that actually think through what algorithms to use and how it all works and optimize lines of code and try to think like a compiler from time to time are grunts to be enclosed in cubicles, while those who think how the general program should work, create UML diagrams of interacting business objects are the lords of their domain.
That makes no sense to me, especially since the drag and drop people use software delveloped by code typers. Or it does make sense in the way that software development has become a feudal industry, like most industries become shortly after they become mass consumed. They have an elite, a clique that behaves like aristocracy, while most members of that industry work their asses off in the employ of these people. This gives a whooole new meaning to the term software revolution :)

So what is this job that I am performing? Am I just a meta-computer? Something high level that understands what it must do and obeys blindly by using a computer? Why is it that I like to code? Is there a difference in my mind between software and a program, so that the term software developer scratches my ears while programmer boosts my ego? And why do most people feel the other way around?

These are questions that I will probably be asking for a long time. Meanwhile, take a look at this wikipedia page, which I found informative: Programming paradigm. Also, consider this little link: Javascript 3D where you can find the explanation on how to do a Wolfenstein like game in Javascript, with only 5 kilobytes of code. You might want to wait a bit until it loads completely or use Mozilla Firefox. I noticed it works faster. Can't believe it? Check it out! That's what programmers do!

GridView Export to Excel Problems

This guy researched why simple methods like export datagrid to Excel don't work with GridViews or other controls. I have also stumbled on this stupid error when trying to use RenderControl to get the output of a UserControl.

Apparently, the entire problem lies with the
Page.VerifyRenderingInServerForm Method
which throws an exception if the page is not currently in the render phase of page processing, and inside the <form runat=server> tags.

Luckily it can be overridden. Here is the bug posting at Microsoft and their suggested solutions. Microsoft removed the page, so I can't show it to you.

This is the actual code for the method in the Page control in NET 2.0. Just override the hell out of it.
public virtual void VerifyRenderingInServerForm(Control control)
{
if (this.Context == null || base.DesignMode) return;

if (control == null)
{
throw new ArgumentNullException("control");
}
if (!this._inOnFormRender && !this.IsCallback)
{
throw new HttpException(System.Web.SR.GetString("ControlRenderedOutsideServerForm", new object[] {
control.ClientID,
control.GetType().Name
}));
}
}

and has 0 comments
Business - Redefining How Software Works

REST (Representational state transfer)

Representational State Transfer

Probably what I am saying here is naive, as I hate XML and don't quite understand the full scope of things like REST, but from what I managed to gather, this system has a few possible advantages: good caching, good division of resources (both computational and data) which should allow for better user in multitask/multiprocessor systems, true native use of XML (or any other format :D), therefore saving a lot of time from serializing, instantiating, deserializing, etc.

If what the first article says is correct, this would prove to be a system both adaptable and scalable, something that programmers seek all the time. It can be spread out on more computers on a net or used on the same computer, with more efficiency and easy of programming than the dreaded web services or SOA.

Personally, I think I wouldn't particularly like programming in a REST way, but one never knows.

Accessing Row based data in an efficient and maintainable manner - The Code Project - C# Database

This is a nice and simple article about accessing data from a lot of datarows. While using the string index will make the code more readable, using the integer index will make the code faster. The solution? Get the numeric indexes at the beginning of the loop, based on string indexes. Assert the indexes exist for better debugging. Very elegant. Also, check out the user comments, which are pretty good and to the point.

Code example:

int customerIDIndex = table.Columns.IndexOf("customerID");
int customerFirstNameIndex = table.Columns.IndexOf("firstName");
int customerLastNameIndex = table.Columns.IndexOf("lastName");

System.Diagnostics.Debug.Assert(customerIDIndex > -1,
"Database out of sync");
System.Diagnostics.Debug.Assert(customerFirstNameIndex > -1,
"Database out of sync");
System.Diagnostics.Debug.Assert(customerLastNameIndex > -1,
"Database out of sync");

foreach(DataRow row in table.Rows){
customer = new Customer();
customer.ID = (Int32)row[customerIDIndex];
customer.FirstName = row[customerFirstNameIndex].ToString();
customer.LastName = row[customerLastNameIndex].ToString();
}//end foreach

How to include a header on each page when printing a DataGrid - The Code Project - .NET

There is a simple solution for printing tables with repeating headers on each printed page. It involves CSS styling of the THEAD section of a table. Unfortunately, neither DataGrids nor GridViews render the THEAD tag. Somehow, Microsoft seems hellbent against it. So either create a control that renders THEAD, then add "display:table-header-group;" to the THEAD style, or use this Javascript function:



function AddTHEAD(tableName)
{
var table = document.getElementById(tableName);
if(table != null)
{
var head = document.createElement("THEAD");
head.style.display = "table-header-group";
head.appendChild(table.rows[0]);
table.insertBefore(head, table.childNodes[0]);
}
}
Update:
Building a GridView, DataGrid or Table with THEAD, TBODY or TFOOT sections in NET 2.0

Using SQL Server instead of Access files:
1. Run aspnet_regsql.exe (from the NET Framework 2.0 folder)
2. Add to web.config (inside the configuration tag):
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=localhost;Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
(that's because LocalSqlServer is already defined by default. Really dumb)
3. Go to the Website menu in Visual Studio -> ASP.NET Configuration and create users, roles and access rules.

Logging out programatically:
FormsAuthentication.SignOut();

Changing settings for the membership (in system.web section):
<membership defaultProvider="CustomizedProvider">
<providers>
<remove name="AspNetSqlMembershipProvider"/>
<add name="AspNetSqlMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
applicationName="/"
requiresUniqueEmail="false"
minRequiredPasswordLength="1"
minRequiredNonalphanumericCharacters="0"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
commentTimeout=""/>
</providers>
</membership>

Scripting Center
Download details: Scriptomatic 2.0

WMI or Windows Management Instrumentation is Windows service who's basic function if to get information from a computer (even remote ones), but that has been upgraded to be able to also put information or run stuff. Weird little things like the manufacturer of the sound card or information about installed and running programs can be extracted with WMI, but also reading from a database or automate Sysadmin tasks for all the computers in the network, etc.

Well, this blog entry is not supposed to explain what WMI is, but to introduce the Microsoft Scripting Center. The link is above, it shows you how you can access and display/modify, etc information with WMI using scripts. The tool Scriptomatic 2.0 (download link above) automatically creates scripts in vbs, js, python and perl to list information in any of the WMI classes. The Scripting Center has a lot of scripts, categorised, so that you can download them and use them directly or with little modification, also tutorials and other useful links. Check it out!

I had problems with WindowsFormsParkingWindow and a lot of the references on the web pointed to this blog article. Unfortunately, the page was not available when I started searching for it. The only place I could find it was google cache, god bless their big googly hearts :) Therefore I am reprinting the content here, maybe it helps people:

=== WindowsFormsParkingWindow a.k.a The devil ===

I have been working on an application for a few weeks and suddenly it started freezing up for no reason. After copious amounts of swearing and breaking keyboards I found a hidden window in the windows task list. It was called - WindowsFormsParkingWindow. My new worst nightmare.

Nothing seemed to stop this issue from killing my program. After more swearing and cursing I found that this error happened after ALT-Tabbing away from my app and back into it. The parking window would appear and my app would die. I ran WinSpy++ and made the hidden window visible. Behold the glory of the following...

The hidden window contained a user control that I had previously removed off the form. This might not make sense to you now but let me explain the significance. When you remove a control from a form/panel, it gets put onto a WindowsFormsParkingWindow until you put it back onto the panel/form. So the WindowsFormsParkingWindow is kind of like an intermediate place windows keeps user controls before they are put into containers.

You might ask now - "What has that got to do with my app freezing?" Well, I'll tell you exactly why... Because when you remove a control from a panel/form and it has focus, the focus stays on the control (which is now on an invisible form). That's why events fail to fire and the app becomes unresponsive.

The solution? Easy...

Instead of using pnlParent.Clear() or just removing the control you need to do the following:

1. Remove the focus from the current user control by setting it to the parent form.
2. Remove the desired user control by using the ParentControl.RemoveAt( indexOfUsercontrol )

This should clear up the issue.

I somehow managed to add to one of my Visual Studio 2005 Web Projects a webservice that had the code written "inline" meaning the <%@ WebService Language="C#" Class="WService"%> tag, followed by the C# code. While Visual Studio has a decent Intellisense functionality in asmx files, ReSharper doesn't. So I felt the need to move the code into a codebehind file. You would think that adding the Codebehind="WService.amsx.cs" would be enough. No, it isn't! As the codebehind model for VS is to have the codebehind in a compiled dll, an error like "Cannot create type WService" will annoy the hell out of you. The solution is to add the cs file into the App_Code directory.
<%@ WebService Language="C#" Class="WService" Codebehind="~/App_Code/WService.asmx.cs"%>

I've tried compiling and using a dll from the net for a Pocket PC and, even if the compilation of the source worked, when trying to add it as a reference, I got an error and the dll would not show in the references. However, a lot of other errors occurred later on, as if the dll was still referenced. Reading the csdproj file directly, I noticed that the reference to the dll was there, but that every time the project was loaded, the same error occurred and the reference did not show. The only solution is to remove with a text editor the XML entry from the csdproj file.

Also, VS2003 hangs periodically after a few debug-deploy cycles, usually when trying to stop debugging, using 100% CPU and freezing. This might also be related with version 2.0 of ReSharper which I have installed, but somehow I doubt it, cause I love the guys at JetBrains! :) The only solution is to kill the process, which will close VS2003, then restart it and reload the project.

Another issue is with the file on the Palm being in use while you try to deploy. The solution is to get to the Palm Control Panel, go to Memory, select the Running Programs, kill any program that has the same name as the program you want to deploy and anything that looks like "Client".

There are other issues, but I don't care to remember them all B-)

How to: Reference ASP.NET Master Page Content:
You must use a MasterType tag in each page to define the exact master page used. After that, all public members and properties in the MasterPage will be available in code as
Master.PropertyOrMember="RightHand";