Tips and Trickshttp://www.geekzilla.co.uk/Innovation Team's dumping grounden-usTue, 10 Jun 2003 04:00:00 GMTTue, 10 Jun 2003 09:41:01 GMTGeekZilla.co.ukeditor@GeekZilla.co.ukwebmaster@GeekZilla.co.uk Display CreateUserWizard Error Messages using a ContentTempate http://www.geekzilla.co.uk/view521AFCB5-0CB8-4FFD-A45A-2EE24ADC7FFE.htm CreateUserWizard Error Messages using a ContentTempate In our latest project we are implementing Membership, Roles and Profiles. I've used these before, but never really had the need to exploit all the features. The business requirements of the system have meant that I have had to implement a custom CreateUserWizard ContentTemplate, which is great feature of the control. I can set all of the error message properties, but I just couldn't work out how to get my custom error text onto the screen. I even tried putting code into the '''OnCreateUserError''' event to trap an error and display the error text, and this doesn't work because the error text in the event isn't what you specified in the control. After trawling the web, I found the solution. The Control must look for this literal when it is in error, and populates it. :-) How easy was that?! I'd normally close by suggesting a beer, but its too early on a sunday.. :-( Hope this helps someone. 12/8/2007 http://www.geekzilla.co.uk/view521AFCB5-0CB8-4FFD-A45A-2EE24ADC7FFE.htm Terrible Spelling in VS2005 becomes a thing of the past http://www.geekzilla.co.uk/view05F3A146-05EE-4837-93D3-68B107B916DB.htm Terrible Spelling in VS2005 becomes a thing of the past Countless numbers of times I have had to cut and paste text from my HTML into Word to spell check it because there isn't a spell checker in the VS IDE. Well the hassel has gone with this excellent plugin I found on Mikhail Arkhipov's Blog. http://blogs.msdn.com/mikhailarkhipov/archive/2006/04/17/577471.aspx Easy to install, if it doesn't appear in your tools menu straight away, register the vsspellchecker.dll in '''C:\Program Files\HTML Spell Checker Add-In''' No more bad spelling :-) 16/6/2007 http://www.geekzilla.co.uk/view05F3A146-05EE-4837-93D3-68B107B916DB.htm Clear your Visual Studio Recent projects list http://www.geekzilla.co.uk/view3D4F4B85-F404-4463-B0BA-BA961D8C1C44.htm Clear your Visual Studio Recent projects list If you do a lot of tinkering in VS2005 and you want to clear down your recent projects list, this can be easily achieved by some simple registry editing You will find a list of files in this area of the registry, simply delete the entries. If you break the numbering you will need to renumber the entries after the one you have removed or the list will be truncated at that point. Hope this helps you tidy up your recent projects ;-) 15/6/2007 http://www.geekzilla.co.uk/view3D4F4B85-F404-4463-B0BA-BA961D8C1C44.htm Json converters lacking in Microsoft AJAX RTM http://www.geekzilla.co.uk/viewFB6CC06E-A638-428B-8A60-8C64887BA750.htm Json converters lacking in Microsoft AJAX RTM Having spent some time developing a project using a CTP version of Microsoft Ajax ("ATLAS" back in the day) I finally came to migrate the project to the RTM version. After uninstalling the CTP release, and installing the RTM release I wasn't surprised to see the project no longer compile. But once the basic problems were fixed (mainly name changes, tag prefixes, and a new [scriptservice] attribute for your web service classes) I was still seeing errors in the application. One of the main problems were errors of 'System.InvalidOperationException: A circular reference was detected ...' when calling a webservice that returned a DataTable or DataRow[]. The UI of this project was pretty much built on client-side calls to update and select data in this way, so suddenly I had a lot of select methods that stoped working (and in a project with 300+ stored procedures behind the scenes this was a headache!) I expected a few niggles but what I didn't expect was that the Json converters for DataTable and DataRow were no longer included (DataSet too I guess, but I wasn't using that in this project). I noticed that the references to the converters in the web.config were commented out and replaced with: ... 'that doesn't look right', I thought. Having seen online that the January 2007 CTP release had solid Json converters included I decided to use these rather than write my own (although that does look interesting :-) ). It turned out to be not too hard to get this working. All that is required is to replace the converter/add elements with those from the January CTP And to add the January CTP Microsoft.Web.Preview.dll file to the bin directory of your project (or the Global Assembly Cache if you prefer). To get file with the converters I had to download the Jan CTP, install on a virtual machine (I didn't want to run the CTP install after the RTM one) and copy the one file I wanted. To save you the hassle I have attached the file below. I was using a pretty old beta and in some cases had to refer to column values via a getProperty method... ...these had to change to directly accessing the column value as a property... ...which I prefer, even though it involved rather a lot of typing in this instance. Hey presto, my javascript was able to see my data again. That was all I had to do to migrate this section of my project. If you have the same problem with passing Data tables out of web services back to javascipt, then follow the tips above and all will be well :-) 6/5/2007 http://www.geekzilla.co.uk/viewFB6CC06E-A638-428B-8A60-8C64887BA750.htm Visual Studio Orcas Beta 1 Available http://www.geekzilla.co.uk/view70C3A1AB-6AC2-4723-9354-539BFE608C63.htm Visual Studio Orcas Beta 1 Available You can now download Visual Studio Orcas Beta 1. Use one of the links found here: * {The Team Suite Edition on a Virtual PC}http://www.microsoft.com/downloads/details.aspx?FamilyId=36B6609E-6F3D-40F4-8C7D-AD111679D8DC&displaylang=en * {Team Suite on a Virtual PC with Team Foundation Server}http://www.microsoft.com/downloads/details.aspx?FamilyId=A13CAE3D-8EC1-4D84-8620-D82E832391D7&displaylang=en * {Download the C# Express Edition}http://msdn.microsoft.com/vstudio/express/future/visualcsharp/default.aspx If you are trying to decide which link to use, the main consideration for most people will be size. With the exception of the C# Express Edition, these downloads tend to have a hefty girth of approximately 5 GB. The Express Edition is much, much smaller. On the other hand, it has fewer features, but many developers will find it sifficient for their needs. If you are upgrading from the 2006, May LINQ CTP, you might want to view this page, which shows which API's have changed since that time. The LINQ samples for Beta 1 are also available for download. You will download an MSI which by default will install the samples as a zip file to your Program Files directory. A link will appear in your menu, and you can unzip the files to your Documents directory or some place where you have read/write permissions. More Info Here : http://msdn2.microsoft.com/en-gb/vstudio/aa700831.aspx 21/4/2007 http://www.geekzilla.co.uk/view70C3A1AB-6AC2-4723-9354-539BFE608C63.htm Typed Masterpage reference http://www.geekzilla.co.uk/view674ECBC1-7CC3-486E-A580-E4B048E1E3D5.htm Typed Masterpage reference ASP.NET master pages are pretty handy and here is a simple tip to make them even easier to use. Using the MasterType reference in your content page allows you to refer to your master page properties without having to cast it to your master page type everytime. For example... allows me to write... rather than... Which saves you a little typing and provides intellisense 22/9/2006 http://www.geekzilla.co.uk/view674ECBC1-7CC3-486E-A580-E4B048E1E3D5.htm Bug in VS2005? Using Typed DataSets with SQL 2005 and stored procedures http://www.geekzilla.co.uk/view72C81AA0-44A5-4E2C-8903-B1EA7D7643EA.htm Bug in VS2005? Using Typed DataSets with SQL 2005 and stored procedures I have been a fan of typed datasets since I started using them in VS2005. Using the feature with SQL Express/stored procedures, Express/SQL Statements, SQL Server/SQL Statements all generate my DAL just fine. However, I have found a couple of problems with them when using them with full SQL Server 2005 and stored procedures. '''Problem 1:''' The first problem is basically that the wizard generates stored procedures in the Schema of the user in the connection string. Regardless of whether SQL user or Windows Authentication are used. You probably wil not have created this schema in the database and so the wizard works fine until the finish step where you see the following message... You might change the default Schema to dbo for the user, the wizard ignores this and performs 'CREATE PROCEDURE [user].[spName]...', very annoying. So, you create a schema in your database with the name of the user (and the user access to it) and this problem is resolved. '''Problem 2:''' The next problem you will see is the message: The reason for this is that the stored procedures are created in the user schema whilst the GetData/Fill/insert/update/delete methods still use the dbo Schema. I couldn't find a way to stop this other than changing the properties of the table adapter manually after configuring. However you may note that GenerateDBDirect methods is still set to true in the table adapter properties and the methods are infact generated. This results in ... '''Problem 3:''' When you run your code you see a run time error "Could not find stored procedure 'dbo.yourProcName' " What I ended up doing was to run a script (http://www.geekzilla.co.uk/View4384ACEC-8C9D-452A-83F6-230FFE43C17B.htm) to move my user.spXXX to dbo.spXXX , not ideal but the Dataset works fine after this. '''All sorted...''' Once you aware of what the wizard is doing - creating in user schema and referring to dbo schema - it becomes quite easy to cope with (if not agree with). For a while its behaviour seemed quite random, especially as I had some existing procs in the dbo schema and so some tables worked fine as they created new procs in the user schema and pointed at existing ones in the dbo schema. My final thought is - I get the impression Typed Datasets wasn't tested with SQL Server and stored procedures. But this won't stop me from using them. I hope this is fixed in a service pack soon. 14/9/2006 http://www.geekzilla.co.uk/view72C81AA0-44A5-4E2C-8903-B1EA7D7643EA.htm Return new identity from Strongly Typed Dataset DataTable.Insert method http://www.geekzilla.co.uk/viewF2737CEE-4FCE-4215-B8CA-74D77EF64A5F.htm Return new identity from Strongly Typed Dataset DataTable.Insert method Datasets are pretty good at auto generating stored procedures and wrapping c# code around them for you. However with the insert method you often want to do something with the object that you have just inserted. Fortunately there is an easy way to get the Sproc and the c# method to return a reference to the object. Firstly edit your insert stored procedure adding a @return parameter and a line after the insert to set this to a suitable value. The exmaple below assumes that you are using bigint identity fields. Note that SCOPE_IDENTITY() is similar to @@IDENTITY except its scope is limited to the current command and so improves scalability. Now when you save the Dataset you see that the insert method takes two parameters, the second being a nullable long. My first thought was that Datasets should be the end of editing stored procedures but I am still impressed that the c# method declaration changes accordingly. You can call the updated method in the following way. the long? just means nullable long. After filling the table you can now use the FindByxxxID functions of the DataTable to return the DataRow object. 27/7/2006 http://www.geekzilla.co.uk/viewF2737CEE-4FCE-4215-B8CA-74D77EF64A5F.htm Strongly Typed DataSets and GridViews http://www.geekzilla.co.uk/viewF9581DAE-CCF8-49FF-844C-7498603E0005.htm Strongly Typed DataSets and GridViews If you are anything like me you don't enjoy writing 5 or 6 stored procedures for each business object in your solution. If you do, then click here to read more about T-SQL! http://www.geekzilla.co.uk/Browse.aspx?CategoryID=32 For the rest of you I will add some notes about my recent experience with DataSets. Within VS2005 (or the express versions) you can drag a database table onto a DataSet object (an .xsd file generate using the 'Add Item' menu). This generates a DataTable and DataTableAdapter with the four standard SQL statements (Select, Insert, Update, Delete). You can then easily link a GridView to this TableAdapter via an ObjectDataSource. You then run the page it all looks fine, you click the Edit button and make some changes and then click Update. '''ObjectDataSource 'ObjectDataSource3' could not find a non-generic method 'Update' that has parameters: TestString, original_TestId, Original_TestString.''' Then you become less impressed, you have also clicked the Delete button first and noticed that it just didn't work. At this point you might look at the SQL that is automatically generated.... Hmm, I would have been happy with: If you right-click and configure the tableadapter (from within the xsd file) accepting defaults all the way through then some SQL rather closer to my expectations is generated. You save the DataSet file and run again but still get the same error. However, if you search for this error on google (thanks Barry) you will find that setting the Gridview column for the primary key to be '''readOnly=false''' this resolves the error. At this point we have a TableAdapter working with a GridView. Its a shame that I couldn't leave out the steps above - but then I guess there would be no point to this article :-) To summarise, the TableAdapters work well but are let down by the default SQL generation. For all the discussion about SQL above I didn't have to hand craft any SQL statements to get this to work. But I did have to run through the configure wizard to generate useful SQL. The ReadOnly parameter is a default of the GridView, but still you would expect the two to work together better than they do. 12/7/2006 http://www.geekzilla.co.uk/viewF9581DAE-CCF8-49FF-844C-7498603E0005.htm Intellisence not working in web.config? http://www.geekzilla.co.uk/viewED8AD2FE-66D4-4BA9-822D-17A5E89F5A8D.htm Intellisence not working in web.config? Visual Studio 2005 has an interesting "feature" where Intellisence will not pop up when you're editing a web.config file. Annoying eh? Well, I found that removing the '''namespace''' from the '''configuration''' tag kicks it all back into life. Change the following line to 28/6/2006 http://www.geekzilla.co.uk/viewED8AD2FE-66D4-4BA9-822D-17A5E89F5A8D.htm Handy Keyboard Shortcuts for c# 2005 http://www.geekzilla.co.uk/viewB7B2BFFA-499C-4EAD-8594-E75D9BE4819F.htm Handy Keyboard Shortcuts for c# 2005 The following keyboard shortcuts I find invaluable. It's amazing how many people still use the mouse to do everything. Document navigation ||Ctrl+Tab|| Switch documents|| ||Ctrl+Shift+Tab|| Reverse switch documents|| ||Ctrl+kk|| Drop a bookmark|| ||Ctrl+kn|| Itterate through bookmarks|| ||F7|| Switch from HTML to Codebehind view|| ||Ctrl+-|| Navigate backward through last cursor locations|| Code Navigation ||F12|| Goto Definition|| ||Ctrl+]|| Jump to matching brace|| Editing ||Ctrl+c|| Copy a whole line|| ||Ctrl+v || When a whole line in the clipboard (as above) this will instet a whole copied line.. handy for quick duplication|| ||Ctrl+u|| Change to lower case|| ||Ctrl+Shift+U|| Change to UPPER case|| Macros ||Ctrl+Shift+R|| Record a quick Macro|| ||Ctrl+Shift+P|| Run the quick Macro you just recorded|| Comments ||Ctrl+kc|| Comment out selected lines|| ||Ctrl+ku|| Uncomment selected lines|| Formatting ||Ctrl+kd|| Autoformat selected lines|| 13/6/2006 http://www.geekzilla.co.uk/viewB7B2BFFA-499C-4EAD-8594-E75D9BE4819F.htm Why not on by defaut? Turn on auto HTML attribute quotes in 2005 http://www.geekzilla.co.uk/view5C5B80F9-0442-457D-9086-04CABC8CB54B.htm Why not on by defaut? Turn on auto HTML attribute quotes in 2005 Holy cow! Why wasn't this on by default??? How annoying is it that when typing in the HTML Source editor window Visual Studio doesn't add the "" for you automatically?? If it's going to complain profusely about the missing quotes then add them for me ;-) ... well guess what? It's a setting. http://www.paulhayman.com/resource/quotes2.gif In the '''"Tools Menu"''', under '''"Options"''' choose '''"Text Editor > HTML > Formatting"''' there is a checkbox '''"Insert attribute value quotes when typing"'''. Set this to checked. (Example below) http://www.paulhayman.com/resource/quotes.gif You'll find html coding so much quicker and easier now. 13/6/2006 http://www.geekzilla.co.uk/view5C5B80F9-0442-457D-9086-04CABC8CB54B.htm