ASP.net

36 posts

How to fix yet another You must set this property to a non-null value of type ‘Double’ problem with Entity Framework

The Problem You are coding happily away in Visual Studio 2010, working on your asp.net project, using the entity framework and sql server and you get and you get the following error The ‘Amount’ property on ‘SomeTable’ could not be set to a ‘Decimal’ value. You must set this property to a non-null value of […]

How to fix problems with asp.net, C# and Request.ServerVariables[“HTTP_REFERER”]

The Problem: I recently built a small web app that tracked downloads.   Part of that was using the referring page.  Somehow, for some reason, the url was not being sent along with the request. The Cause: After much travail, I finally noticed that the browser was on page https://www.somedomain.com and the link in question […]

How to fix problems with Coded User Interface Tests

The Problem: You attempt to create a new Coded User Interface Test in Visual Studio 2010, and you get the following error: The following package failed to load: C:Users[File Path Goes Here]Microsoft.VisualStudio.TestTools.UITest.Extension.IE.dll. Coded UI Test is now in an inconsistent state. Remove this package and restart Visual Studio to work with Coded UI Test. The […]

How to do a cool flash notification message in asp.net mvc 3 in 6 easy steps

I pieced all of this together from various sources online, so the code is a bit rough, but here it is: 1.  Create a partial razor view, call it _NotifyBar.cshtml, it contains this: @if (Request.Cookies[“NotifyBar”]!=null) { @Request.Cookies[“NotifyBar”].Value.ToString() X var c = new HttpCookie(“NotifyBar”); c.Expires = DateTime.Now.AddDays( -1 ); Response.Cookies.Add( c ); } 2.  Put this […]

How to Fix the “Service Unavailable” problem in IIS

The Problem: For whatever reason, your website is displaying a white screen with “Service Unavailable” and nothing else. The Cause: There could be many causes, but the one I just discovered was that the application pool had shut down for no good reason. The Solution: In IIS, navigate to “Application Pools”, right click to bring […]

How to create a asp.net gridview hyperlink field with multiple querystring parameters

The Problem: You need to put a relatively complicated link (i.e. the link has more than one parameter) into an asp.net gridview column. The Cause: No cause really, you just need to know the exact syntax The Solution: <asp:HyperLinkField HeaderText=”” Text=”Download Your File” DataNavigateUrlFields=”CategoryID,FileID” DataNavigateUrlFormatString=”FileDownloader. aspx?catid={0}&file={1}” /> You can have as many fields as you like in the […]

How to fix problems with asp.net mvc 3 charts and razor pages

The Problem: You attempt to use the super-cool new charting features in asp.net mvc 3, and all you get is compilation errors The Cause: You are using the old school System.Web.UI.DataVisualization.Charting.Chart namespace The Solution: Delete using System.Web.UI.DataVisualization.Charting.Chart and instead insert using System.Web.Helpers; If you are using the chart code in an actual razor page (and […]

How to fix the asp.net DetailsView data validation problem

photo © 2010 Zyllan | more info ia: Wylio) The Problem: You have the standard asp.net DetailsView control (one of many on that page) and your custom validator refuses to work.  So do all of your standard validators now that you think about it.  Your command button looks like this: <asp:ButtonField ButtonType="Button" ValidationGroup="Main" Text="Add This" CommandName="InsertNewRecord"  /> and all of […]

How to fix the copy file problem in C#

photo © 1918 National Library of Scotland | more info (via: Wylio)The Problem: You need to copy a file from one location on the server to another and cannot remember how. The Cause: It is too short and simple, and easily forgotten The Solution: Just use the following code: public static void CopyAndRenameFile(string OldPath, string OldFileName, string NewPath, string NewFileName)     {         if (File.Exists(OldPath + OldFileName))         {             File.Copy(OldPath + OldFileName, NewPath + NewFileName, true);         }     } That’s […]

How to fix the “Unable to cast object of type” problem

photo © 2008 Justin Gurbisz | more info (via: Wylio) The Problem – you have several asp.net web controls (.ascx files) in your website project and for no obvious reason you suddenly get the error “Unable to cast object of type ‘YourWebControlName_ascx’ to type ‘YourWebControlName_ascx’.”  You recompile and the program works, then stops working.  You […]