You are currently browsing the category archive for the 'Uncategorized' category.
The longer you use asp.net webforms the more likely it is that you will see this:
Exception type: System.ArgumentException
Exception message: Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation=”true”/> in configuration or <%@ Page EnableEventValidation=”true” %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
If you’re lucky enough to have it happen on a dev machine and you know which control is causing the problem you’re most of the way to tracking down the error. Just read this, this and this.
If like me, you can’t track it down, all you’re getting is vague error reports and users who can’t remember what they did (or curiously didn’t even see the error) then you need to know which control actually caused the error.
This is what I did:
Imports System.Net.Mail
Namespace Code.Controls
Public Class TrackingLinkButton
Inherits LinkButton
Protected Overrides Sub RaisePostBackEvent(ByVal eventArgument As String)
Try
MyBase.RaisePostBackEvent(eventArgument)
Catch argExc As ArgumentException
SendPostbackError(argExc)
End Try
End Sub
Private Sub SendPostbackError(ByVal argExc As ArgumentException)
Dim subject As String = "ArgumentException: Additional info"
Dim body As String = String.Format("Exception was caused by the control with ID: {0} and clientId of: {1}", _
Me.ID, Me.ClientID)
Dim msg As New MailMessage("from@somesite.com", "support@somesite,com", _
subject, body)
Dim client As New SmtpClient() client.Send(msg) End Sub End Class End Namespace
And hooked it in with this:
<tagMapping> <add tagType="System.Web.UI.WebControls.LinkButton"mappedTagType="AcademyPro.Code.Controls.TrackingLinkButton"/></tagMapping>
Now all I have to do it sit back and wait for the email to fire and I should be able to track down the error (I hope).
Roy Osherove is giving an hands-on TDD Masterclass in the UK, September 21-25. Roy is author of “The Art of Unit Testing” (http://www.artofunittesting.com/), a leading tdd & unit testing book; he maintains a blog at http://iserializable.com (which amoung other things has critiqued tests written by Microsoft for asp.net MVC – check out the testreviews category) and has recently been on the Scott Hanselman podcast (http://bit.ly/psgYO) where he educated Scott on best practices in Unit Testing techniques. For a further insight into Roy’s style, be sure to also check out Roy’s talk at the recent Norwegian Developer’s Conference (http://bit.ly/NuJVa).
Full Details here: http://bbits.co.uk/tddmasterclass
bbits are holding a raffle for a free ticket for the event. To be eligible to win the ticket (worth £2395!) you MUST paste this text, including all links, into your blog and email Ian@bbits.co.ukwith the url to the blog entry. The draw will be made on September 1st and the winner informed by email and on bbits.co.uk/blog
If you have a web form and don’t want a users input to be saved by a browser for repeated entry later then you need to employ autocomplete attribte of a form.
The HTML below will give you a simple form that the browser should not prompt the user to save the credentials.
You should note, this is not standards compliant, but it does seem to work in chrome, IE and firefox.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<title>Prevent Autocomplete</title>
</head>
<body>
<form id=”payment” autocomplete=”false” action=”#” method=”post”>
<p><label for=”Name”>Name on Credit Card</label><input type=”text” id=”Name”/></p>
<p><label for=”CCNum”>Creditcard Number </label><input type=”text” id=”CCNum”/></p>
<p><label for=”Expiry”>Expiry Date</label><input type=”text” id=”Expiry”/></p>
<input type=”submit” />
</form>
</body>
</html>
I’d like to think that I know a fair amount about core HTML. That said there’s always room to learn more, and yesterday was a case in point.
Until now, when wanting to separate groups of elements in a selection list we’ve always introduced option elements surrounded by extra characters, e.g. (“–Intermediate / Higher /Advanced Higher”) in the example below.
<SELECT>
<OPTION>--National Assessments (5-14)
<OPTION>A
<OPTION>B
<OPTION>C
<OPTION>D
<OPTION>E
<OPTION>F
<OPTION>--Access 1,2,3 / Core Skills
<OPTION>Pass
<OPTION>Fail
<OPTION>--Intermediate / Higher /Advanced Higher
<OPTION>A
<OPTION>B
<OPTION>C
<OPTION>D
<OPTION>--Standard Grades
<OPTION>Grade 1 - Credit Level
<OPTION>Grade 2 - Credit Level
<OPTION>Grade 3 - General Level
<OPTION>Grade 4 - General Level
<OPTION>Grade 5 - Foundation Level
<OPTION>Grade 6 - Foundation Level
<OPTION>Grade 7 - Course Completed
<OPTION>-HNC/HND
<OPTION>Pass
<OPTION>Fail
<OPTION>--NVQ/SVQ
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
<OPTION>5</SELECT>
As a solution this is a bit messy as the user is still able to select the separator options, and therefore relies on client or server validation to prevent this being saved. What a revolution then to find that there is an HTML element that allows you to group together a number of option elements – and it’s called OPTGROUP. Go figure!
In action then, the list above then becomes:
<SELECT>
<OPTGROUP label="National Assessments (5-14)">
<OPTION>A
<OPTION>B
<OPTION>C
<OPTION>D
<OPTION>E
<OPTION>F
</OPTGROUP><OPTGROUP>Access 1,2,3 / Core Skills
<OPTION>Pass
<OPTION>Fail
</OPTGROUP><OPTGROUP label="Intermediate / Higher /Advanced Higher">
<OPTION>A
<OPTION>B
<OPTION>C
<OPTION>D
</OPTGROUP><OPTGROUP label="Standard Grades">
<OPTION>Grade 1 - Credit Level
<OPTION>Grade 2 - Credit Level
<OPTION>Grade 3 - General Level
<OPTION>Grade 4 - General Level
<OPTION>Grade 5 - Foundation Level
<OPTION>Grade 6 - Foundation Level
<OPTION>Grade 7 - Course Completed
</OPTGROUP><OPTGROUP label="HNC/HND">
<OPTION>Pass
<OPTION>Fail
</OPTGROUP><OPTGROUP label="NVQ/SVQ">
<OPTION>1
<OPTION>2
<OPTION>3
<OPTION>4
<OPTION>5</OPTGROUP></SELECT>
It’s browser compliant, and you can style the OptGroup elements different to the Option elements.
Now I can’t wait to see what I can learn today.
At least. that’s what I thought until today.
It’s been a bit of a running joke in our office that being cynical too early in the week is non-productive, and detracts from the job in hand. And so it was that “Cynical Thursday” was born! Why Thursday? Well, obviously Wednesday signifies the middle of the week – still far too early for negative vibes. And who wants to be downcast on a Friday, riding the cusp of the weekend?
Not to break with tradition, today has had it’s fair share of gripes and groans – about work, people, life etc. But today is different. Today our cynicism has reached the level whereby we challenged ourselves to do something about it.
Today, “theoldsewingfactory” has been reborn. This blog is the start of things to come.
No longer will cynicism rule. No longer will we allow our destiny to be taken from our hands. We have a voice. We have talent and skills.
We will succeed.
