Posts

Error : /ScriptResource.axd : Invalid viewstate.

This issue is caused when the ScriptResource.axd querystring parameters can not be decoded on the server. This error can be caused from multiple issues with server configuration or the Browser's interaction with the server. The ScriptResource.axd contains all of the clientside javascript routines for Ajax. Just because you include a scriptmanager that loads a script file it will never appear as a ScriptResource.AXD - instead it will be merely passed as the .js file you send if you reference a external script file. In other words it is what the Microsoft Ajax libraries inject into your HTML to allow them to access their javascript functions they need for page manipulation. ASP.NET will use the machine key to encrypt the ScriptResource.axd (and webresource.axd) url's parameters(in querystring), and by default the machinekey is a randomly generated one which may involve the current time. By default there is a different machinekey on every machine, and it changes when the applic...

Disabling the OkControlId On A ModalPopupExtender

I am using the ModalPopupExtender Ajax extender in .NET to display a modal dailog that takes in some data and saves it to the database. The issue is that the saving the data to the database is a little slow and there is an oppurtunity for the user to press the "Save" button a couple of times before the modal dialog closes. This is because I am handling the OnClick event of the save button, which writes the data and then calls the Hide method of the ModalPopupExtender. It looks a little like this: < asp:Panel ID ="panel" runat ="server" Style ="display: none;" > < asp:Button runat ="server" Text ="Save" Enabled ="true" ID ="saveButton" OnClick ="saveButton_OnClick" /> < asp:Button runat ="server" Text ="Cancel" ID ="cancelButton" OnClick ="cancel_OnClick" /> </ asp:Panel > < ajaxControlToolKit:ModalPop...

Validating and Email Address

Well I am doing it again, writing a form that validates a TextBox to figure out if it is an email address. If I had a ten cents for every time I have written this same for code in ISAPI, IDC/HTX, Classic ASP, ASP.NET and other languages I would be rich.   Once you have the input you need to validate that it really is an email address. There is no way to know for sure, since email is a forward only protocol. Some of the same I have done this in the past include: Check to make sure that there is a @ , which is pretty lame. Use a regular expression to check the email address, a little better. Tonight I was thinking that it would be handy to get the MX record of the domain for the host of the email address. This way I would know if the host name accepted email (or at least the DNS administrator for that domain thought it accepted email) and I would also know that the domain exists and was returning DNS responses.   So search on the Internet for a C# query tha...

Handling Your SQLException By Number

I am working on a bug where I am getting this error: Source: .Net SqlClient Data Provider Description: The server failed to resume the transaction. It is a SQLException from SQL Server, that I want to try/catch in my C# code and handle. The nice thing about SQLException is there is a Number property that you can use to identify the error message from anyother SQL Error. The Number of this exception is 3971 So my C# code looks like this: catch (SqlException sqlException) { switch (sqlException.Number) { case 3971: The Numbers come from the master.dbo.sysmessages table, one of the ways that I find out what number matches what message is be using a query like this: SELECT * FROM master.dbo.sysmessages WHERE description LIKE '%The server failed to resume%' However, it is probably easier to use the debugger, that is if you can catch the error. In this case our bug reporting system was telling me the error, however it is hard to r...

RadioButtonList Error With UpdatePanels

Let's consider this code for a minute: <form id= "form1" runat= "server" > <asp:ScriptManager runat= "server" /> <div> <asp:UpdatePanel runat= "server" ChildrenAsTriggers= "true" > <ContentTemplate> <asp:RadioButtonList runat= "server" ID= "RadioButtonList1" AutoPostBack= "true" OnSelectedIndexChanged= "RadioButtonList1_SelectedIndexChanged" > </asp:RadioButtonList> </ContentTemplate> </asp:UpdatePanel> </div> </form> Code behind: protected void Page_Load( object sender, EventArgs e) { if (!Page.IsPostBack) { String[] items = new String[] { "0" , "1" , "-10" }; RadioButtonList1.DataSource = items; RadioButtonList1.DataBind(); Ra...

Ordering String As Numbers -- Sometimes

We have a varchar(50) in our database called item number. Most of our customers use this as a number, entering numbers. However, some of them for flexiablity (not all square items go into round holes) want to use it as the abstract number, entering in things like: "SC-1002S". The issue came up the other day, that a majority of our users want the numbers they add to sort like numbers, we were sorting this like strings: (1,11,2,22,23,3 ...). So Steve came up with this great idea of a double sort, first trying to CONVERT the string to a number. Here is my T-SQL for the idea: SELECT * FROM Items ORDER BY (CASE WHEN ((ISNUMERIC(ItemNumber) = 1) AND (NOT ItemNumber LIKE '%E%') AND (NOT ItemNumber LIKE '%.%')) THEN CONVERT(int, ItemNumber) ELSE NULL END), ItemNumber First thing to note is that you can use a CASE expression in an ORDER BY Clause. Second thing is that first we try to convert the string to a number, if we can't it is a NULL, secondarly we s...

Hey Compiler Team -- Make My Life Easier

The local Bellingham .NET User Group was blessed by having a speaker from the Microsoft C# compiler team visit and tell us about C# 4.0. One of the things that she kept repeating was that "fill in new feature" was done to save typing. Here is my suggestion for a language change: I do a lot of this: public class X { private int _id; public X(int id) { _id = id; } } Most of the time I have several overloads of the constructor, wouldn't it be nice if I could just write this: public class X { private int _id; public X(int _id) {} } If the compiler sees a variable in the constructor with the same names as a member variable of the class (an illegal syntax already) it would know that I want to assign the member variable automatically. The compiler already has to check for conflicts, so it is doing most of the work already. And it you didn't want this to happen, you could just change the variable name to be unique to the local an...