Home


.Net, SQL and softball. Musings of a software developer with a softball problem

Thursday, February 21, 2008

Event Validation Error

So I just spent the last hour or so here trying to figure out the following error:


Invalid postback or callback argument. Event validation is enabled using 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


So if you've seen this error you no doubt have flat spots on your head from banging your head against the cube wall

The popular message out in the vast expanse of the internet is to just set the EnableEventValidation="false" either in the page directive or in the web.config file. Let me first state that, yes that will work. But more importantly let me tell you what a bad idea this is. This nice little feature protects you from you from Cross site scripting (XSS) as well as many other nasty little things/people that are waiting to take down your site. So just get that idea out of your head unless you feel like writing your own validation code to make sure nothing gets in that you don't want to. Go ahead, I'll wait...

Ok, so now that you forgot about the cheap work around. Here are the two main things to look for (from my experience/research) . One, nested form tags. ASP.Net isn't a fan. Remember if you are using master pages, the child page does not need a form tag, that is in the master page. Second, and this is what i finally figured out was my problem. The postback was coming from an imagebutton inside of a gridview control. I was binding the gridview on each postback. So what was happening was, I was losing the select event when I re-bound the grid. So I stuck the function that was binding my grid inside a conditional !Page.IsPostBack.

So before you go and open up your site for some serious vulnerabilities, check to make sure your coding logic is sound and it isn't something small you've over looked.

Labels:

posted by Tom Becker at | 0 Comments

Wednesday, February 20, 2008

Concatenating values across multiple rows

I had a hard time coming up with a relatively short name for the post, but here is what I wanted to get at. I have been struggling with this for quite some time now, and today I finally found a solution.

I have a base table that has a one-to-many relationship to a cross reference table. And what I wanted to do was create a single row per entry in the base base table with all of values from the cross ref table in a single column concatenated together.

So I looked at creating a pivot table, but that only got me so far. I could get all the different values that were in the cross ref table as columns, but that would give me multiple instances of my base record in the result set.

So, after much research and banging my head against the wall. I came across Tom Kyte's blog and an article called Stringing them Up.

Here is my version of his example. It has a little more in it than his example:


select A.BaseTable_ID,
A.NAME,
A.METHOD_DESC,
A.DATA_DESC,
A.REF_NO,
B.TYPELIST

FROM BaseTable A

INNER JOIN(
select BaseTable_ID,
max(sys_connect_by_path(type_desc, '/ ')) TYPELIST

from (SELECT ID,
type_desc,
ROW_NUMBER() OVER PARTITION BY BaseTable_ID
ORDER BY type_desc) rn
from baseTable A
inner join XRef B
on A.TYPE_ID = b.type_id)

start with rn =1
connect by prior rn = rn-1
and prior BaseTable_ID = BaseTable_ID
group by BaseTable_ID
order by BaseTable_ID ) B

ON A.BaseTable_ID = B.BaseTable_ID

Labels:

posted by Tom Becker at | 0 Comments

SOURCE FORCE AWAY!!!

So I just saw this on Slashdot and it was too good not to pass along to my loyal readers. Hi, Megan (prolly my only loyal reader)!

Is it sad that I really want to get some of these? And notice from the URL, this is not a spoof, Microsoft is actually putting out action figures.

Labels:

posted by Tom Becker at | 0 Comments

Monday, February 11, 2008

Moving items up or down in a listbox

So I really didn't think this was that complicated to do. Changing the order of items that are displayed in a standard list box. Nothing all that fancy. It being a Monday, I decided to try and not think and just to grab some code from somewhere on the internet.

I was surprised by the wide variety of different ways to do this and all of them seemed overly complicated. One involving a nested for loop or another messing with the data source and saying that it only worked when the box was bound. Craziness.

All of this seemed way to complicated. So I broke down and thought about it for a second, and came up with (I think) the easiest way to move an item up or down in a list box control in .Net.


'down button press
Private Sub btnDown_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDown.Click

Dim index As Integer = Me.lbxSortOrder.SelectedIndex
Dim itemCount As Integer = Me.lbxSortOrder.Items.Count
Dim li As ListItem = Me.lbxSortOrder.Items(index)
Dim newIndex As Integer

If index = itemCount - 1 Then
newIndex = index
Else
newIndex = index + 1
End If

Me.lbxSortOrder.ClearSelection()
Me.lbxSortOrder.Items.Remove(li)
Me.lbxSortOrder.Items.Insert(newIndex, li)
li.Selected = True

End Sub



The up button press is the same exact thing except the text on the index needs to look like this:


   
If index = 0 Then
newIndex = 0
Else
newIndex = index - 1
End If



And thats it. I know it was simple, I thought about not posting this cause of its simplicity, but by looking what else was out there, I'll add my two cents.

Labels:

posted by Tom Becker at | 1 Comments

Friday, February 1, 2008

New Theory

So I think that amount of liquid in your bladder is directly proportional to the amount of time you spend at red lights while driving.

that is all.

Labels:

posted by Tom Becker at | 0 Comments