Posts

Showing posts from April, 2009

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...