ASP.nethttp://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 Launching an Ajax ModalPopupExtender from JavaScript http://www.geekzilla.co.uk/view38736C2B-BAD3-418A-A5B0-DAC4F1A5A83A.htm Launching an Ajax ModalPopupExtender from JavaScript This is an updated version of the earlier (and very popular) {Atlas article}http://www.geekzilla.co.uk/ViewDAAE6AAB-0369-45C2-BE78-B8E6F876B4F4.htm It is by far the simplest way to launch an Ajax ModalPopupExtender from javascript. The groundworks Add a hidden link for ModalPopup Extender to attach to('''which will NEVER be used''') Add the ID of the hidden link to the ModalPopupExtender Showing the modal popup Now you've done this, in Javascript, you can display the modal quite easily... here's how. Hiding the modal popup Just as easy... #c#$find('MyMPE').hide(); 10/7/2007 http://www.geekzilla.co.uk/view38736C2B-BAD3-418A-A5B0-DAC4F1A5A83A.htm ASP.NET Framework 1.1 Validation not working in IE7? http://www.geekzilla.co.uk/viewFF2FB9D4-28F7-4289-BEB3-6EA081A003EB.htm ASP.NET Framework 1.1 Validation not working in IE7? I recently had a problem with an old '''Framework 1.1''' website where the form would not post back if the page contained validators (CustomValidators to be exact). It caused me to do a lot of googling and in the end some javascript debugging. It was a strange problem, the site worked fine in IE6 and Firefox; just IE7 failed. Searching the web I was suppried that nobody else was complaining about this.. surely it was a 1.1 IE7 bug?? First clue In the onSubmit attribute of the form tag there is a call to '''ValidatorOnSubmit()'''. When Alerting this in JavaScript it returned '''"Undefined"''' I checked that the scriptmaps were ok and even reinstalled them using '''ASPNET_REGIIS -s <path>'''. Still no dice. The solution It turned out that .net '''Framework 1.1 SP1''' had been installed on the server but this site had local copies of the pre SP1 '''WebUIValidation.js''' file. I replaced the files with the correct ones and things started to work... sort of.. Problems with '''pre SP1''' code and the CustomValidator control The validation now triggered. Slight problem, it always failed, without even doing the postback it needed to perform server-side validation. The solution was to add a dummy custom validator function to allow client validation to pass client-side checks before doing server-side validation. #h#<ASP:CUSTOMVALIDATOR ClientValidationFunction="customvalidatorDummy" ... /> 4/7/2007 http://www.geekzilla.co.uk/viewFF2FB9D4-28F7-4289-BEB3-6EA081A003EB.htm LoginStatus not logging users out? http://www.geekzilla.co.uk/viewEDD6EAD5-E7AD-401F-A471-79EFF5C01A04.htm LoginStatus not logging users out? Have you noticed your '''LoginStatus''' control doesn't log the user out when you click '''Logout'''? Well, to fix this all you need to do is add an '''id''' attribute. This works This doesn't work Searching the web, there are a lot of people complaining that the LoginStatus doesn't work properly. Solutions are rare, special thanks to Ric Hayman for finding this. 18/6/2007 http://www.geekzilla.co.uk/viewEDD6EAD5-E7AD-401F-A471-79EFF5C01A04.htm XMLHTTPRequest in Stored Procedure http://www.geekzilla.co.uk/view24CF9B2B-4099-4ED7-B360-89B14C11DAE8.htm XMLHTTPRequest in Stored Procedure I recently had a requirement to call a webservice from a stored procedure. I looked into doing this by writing a CLR assembly in SQL 2005. There were a few articles online describing this but working in a large organisation I knew that getting the thing working on my development was only 20% of the battle. The XML serialisation of the web service request/response cannot be done natively, a separate assembly needs to written to achieve this, using a tool such as SGEN.exe. Basic objects such as HTTPRequest are not available in the SQL CLR so you can't just avoid the serialisation. Even once I had all that working, the idea of our database team deploying assemblies to their databases just seemed like a dream. So I looked for a simpler method and found that I could create an XMLHTTPRequest within a stored procedure much like I would in client-side code for an ajax solution. The stored procedure is below... You also need to enable Ole Automation for this database using... So basically your T_SQL can now make http requests, but not web service requests. The page I am requesting will be written in C# and will make the web service request itself, in an environment that is not so restricted as the SQL CLR. The added benefit is that this does not require 2005 to work, it should work on any SQL Server database v7 onwards Please beware: Your application login will need access to run the sp_OAxxx extended procedures, so you will need to ensure that this isn't something that just anyone can login as. I have read that teh user needs to in the sysadmin role - I have found that just GRANTing EXECUTE permissions for your user on each xp is enough. Also, do not make http calls from within a trigger, this can potentially cause really bad performance, especially where the web server is not reachable or responding for whatever reason. 16/5/2007 http://www.geekzilla.co.uk/view24CF9B2B-4099-4ED7-B360-89B14C11DAE8.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 Handy fake latin generator http://www.geekzilla.co.uk/viewB20C8CB9-EB60-4C33-9BC2-A9506E5EF4D8.htm Handy fake latin generator 4guysfromrolla have a handy "fake latin" generator. It allows you to specify the number of paragraphs to generate. Source available too, although old asp. http://www.4guysfromrolla.com/demos/latin.asp?paras=2 18/4/2007 http://www.geekzilla.co.uk/viewB20C8CB9-EB60-4C33-9BC2-A9506E5EF4D8.htm CAPTCHA Server Control http://www.geekzilla.co.uk/viewD5ACA281-0AAC-4C06-A411-8BAE9FCDED8D.htm CAPTCHA Server Control I have been searching Google for a way to quickly implement CAPTCHA on one of my web sites and came across this article at The Code Project. http://www.codeproject.com/aspnet/CaptchaControl.asp http://www.codeproject.com/aspnet/CaptchaControl/captcha-control.png 4/1/2007 http://www.geekzilla.co.uk/viewD5ACA281-0AAC-4C06-A411-8BAE9FCDED8D.htm Google Applicance - googleoff / googleon Tags http://www.geekzilla.co.uk/viewC8614968-56ED-4729-9C12-F01677DAC412.htm Google Applicance - googleoff / googleon Tags '''I came across these recently... thought I'd share''' ;) The googleoff/googleon tags disable the indexing of a part of a web page. The result is that those pages do not appear in search results when users search for the tagged word or phrase. For example, some developers use googleoff/googleon tags to comment out a navigation bar in static HTML pages. You can use googleon/off to tell the Google Search Appliance to ignore portions of a page. Insert <!--googleoff: index--> at the point you want the Google Search Appliance to stop indexing, then insert <!--googleon: index--> where you want it to resume indexing the page. You can also use the tags to avoid indexing anchor links leading to another web page. You can use either of the following to prevent the words "chocolate pudding" from appearing in the snippets. The googleon/googleoff tags are index, anchor snippet, all. Here's how they are used. index tag Words surrounded by the googleon/off tags will not be indexed as occurring on the current page. A page containing: has the terms "fish" & "mackerel" indexed for that page, but will not index "shark" for the page. It's possible, however, that the page could be a search result for the search term "shark", since "shark" may occur elsewhere on the page, or in anchortext for links to the page. anchor tag "Anchortext" surrounded by the googleon/off tags and occurring in links to other pages will not be indexed as words associated with the other linked-to pages. A page containing: will not cause the word "shark" to be associated with the page "linked_to_page.html". Otherwise, this hyperlink could cause the page "linked_to_page.html" to be a search result for the search term "shark". snippet tag The text surrounded by googleon/off tags will not be used to create snippets for search results. all tag Turns on all of the attributes: index, anchor, and snippet. The text surrounded by googleon/off tags will not be indexed, followed to another linked-to page, or used for a snippet. _thanks to Google for this content_ 27/9/2006 http://www.geekzilla.co.uk/viewC8614968-56ED-4729-9C12-F01677DAC412.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 Web service calls from javascript using ATLAS (part 3) - Complex properties http://www.geekzilla.co.uk/view7DA902AA-513E-48D2-AD02-0F1A1946A999.htm Web service calls from javascript using ATLAS (part 3) - Complex properties Part two covered returning objects with multiple properties from a webservice and accessing those properties from javascript. This article demonstrates that even 'complex' properties are supported by the ATLAS framework. A complex property in this context is one like below: The getVcard method returns some HTML in the vCard microformat. Your javascript stays nice and simple as below... The reason this works is that the javascript object is given each property from the .NET object by the ATLAS framework. If there was a property that showed the current time then the javascript version of the property would always show the time at which it was created. I have found this to be a useful to keep my code/logic where I want it - not embedded in HTML! 25/8/2006 http://www.geekzilla.co.uk/view7DA902AA-513E-48D2-AD02-0F1A1946A999.htm Web service calls from javascript using ATLAS (part 1) http://www.geekzilla.co.uk/view91E6FCCB-DB0A-499C-A2CC-9854452D2086.htm Web service calls from javascript using ATLAS (part 1) ATLAS provides a fantastic mechanism for making web service calls from javascript code. Take the simple web service below... You need to add reference to this web service to your ASP.NET page. This is achieved using the ScriptManager tag as in the example below... Infact only the Services and ServiceReference elements are added to the basic scriptManager tag. Note taht there seems to be a limitation in the CTP that I am using where the web service needs to be in the same web site as your project. This is a serious limitation but it shouldn't be too hard to create a proxy for any web service runing elsewhere until this is fixed in the next CTP. You can now make JavaScript calls to the web service as shown below... I hope you find the example useful in your own applications. 25/8/2006 http://www.geekzilla.co.uk/view91E6FCCB-DB0A-499C-A2CC-9854452D2086.htm Extending Strongly Typed Datasets http://www.geekzilla.co.uk/view6FFCCB67-2483-437D-A6B6-08B378B5B23C.htm Extending Strongly Typed Datasets Strongly Typed Datasets are a rather nice addition to VS2005 (they don't lend themselves well to acronyms however) You still need to create a database and tables and realationships but using STDs saves a writing huge amount of code. If this code were generated by hand or by a utility such as CodeSmith then the classes could just be edited to add function as required (though most of the benefits of code generation are lost once the generated code is edited). The STD source is of course auto-generated from the xsd file, a convienient way to view the C# source is to type the STD name and use the context menu to 'Go To Definition', or press F12. This will open a c# source file with a guid name. You can edit this file but it will be overwritten each time the xsd is compiled. You can add new methods and properties to the STD classes by using partial classes. First create a new cs (or vb if you swing that way) file with the filename same as your xsd - for example 'ObjectSTD.cs'. Edit the class definition adding the partial keyword as below. You can add a new method to the ObjectRow class within the ObjectSTD class with the following code... Note that private properties and methods are available and intellisense supports these. 23/7/2006 http://www.geekzilla.co.uk/view6FFCCB67-2483-437D-A6B6-08B378B5B23C.htm Serializing abstract classes to XML http://www.geekzilla.co.uk/viewA9CF69B4-0C40-4CEE-A590-496D9EB09C0E.htm Serializing abstract classes to XML Digg it: http://digg.com/programming/Serializing_abstract_classes_to_XML_in_c It is often useful to have abstract classes with several derived types to allow use of strongly typed lists and the such. For example you might have a DocumentFragment class which is abstract and two concrete classes called TextDocumentFragment and CommentDocumentFragment (this example from Willis). This allows the creation of a List<DocumentFragment> property which can contain objects only of those two types. If you attempt to create a WebService that returns this list you get an error but this is easy to get around with the code below.... The XmlInclude attributes tell the class that it might be serialized to those two derived classes. This generates an attribute in the DocumentFragment element specifying the actual type, as below. Any additonal properties specific to the derived class will also be included using this method. 18/7/2006 http://www.geekzilla.co.uk/viewA9CF69B4-0C40-4CEE-A590-496D9EB09C0E.htm Parser Error Message: Ambiguous match found. http://www.geekzilla.co.uk/view627399E1-8F4D-4A0F-B60F-3FFC7EAFCCC8.htm Parser Error Message: Ambiguous match found. VS 2005 Only. This can be an annoying error, but it is usually caused by one thing. If you add an object to your html source such as By default this will be instatiated in the partial class that is created by Visual Studio 2005. ""However"", there is nothing to stop you specifing the object in the codebehind as well such as And while you are running in Dev this will continue to work, but as soon as you do a release build you will get the Parser Error Message when trying access the page. A pain but when you know where to start looking it does make it easier to solve the problem. 13/7/2006 http://www.geekzilla.co.uk/view627399E1-8F4D-4A0F-B60F-3FFC7EAFCCC8.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 Changing the password rules for Forms Authentication http://www.geekzilla.co.uk/viewBD8CFE61-E9B7-432B-8672-089E4962A52F.htm Changing the password rules for Forms Authentication An annoying feature of the forms authentication controls shipped with VS2005 is that it forces users to enter non-alphanumberic characters in their passwords by default.. e.g. password would have to be password! Fortunately, this option can be turned off by adding a membership provider section to your web.config The following setting controls the non-alphanumeric.. Below is an example of what you need to add to the '''<system.web>''' section 28/6/2006 http://www.geekzilla.co.uk/viewBD8CFE61-E9B7-432B-8672-089E4962A52F.htm Enabling HttpGet and HttpPost for web services http://www.geekzilla.co.uk/viewD5D13AF7-0E86-46F2-A954-F789132A6B5F.htm Enabling HttpGet and HttpPost for web services If your web application needs to accept incoming webservice method requests based on the '''GET''' and '''POST''' protocols then add the following lines to your ''web.config'' file. #h#</configuration> 24/6/2006 http://www.geekzilla.co.uk/viewD5D13AF7-0E86-46F2-A954-F789132A6B5F.htm Missing VS2005 Templates http://www.geekzilla.co.uk/viewCA97A7D8-E9B9-49A8-BE1F-1CE923F000D4.htm Missing VS2005 Templates If you are having problems with missing VS2005 templates, then the following command run from the VS2005 command prompt may resolve your problems. devenv /installvstemplates 19/6/2006 http://www.geekzilla.co.uk/viewCA97A7D8-E9B9-49A8-BE1F-1CE923F000D4.htm Error in Line 3? http://www.geekzilla.co.uk/view24F4A0DD-5DFE-42C8-B05F-B2415000AEF2.htm Error in line 3 Some websites report an error in line 3 when using the asp.net controls such as login. We recently tracked this error down on one of our sites to the use of custom HttpHandlers. All requests to anything other than *.aspx were routing through our own handler.. Adding the following to the web.config fixed the problem 13/6/2006 http://www.geekzilla.co.uk/view24F4A0DD-5DFE-42C8-B05F-B2415000AEF2.htm