INFO-BUG: GridView Double-Post Problem

G

GregG

This is information for those who may have been bitten by the
"double-post" problem in GridView controls. I've been messing with
ASP.Net about a week, and have uncovered an annoying 'feature'.
Never bothered with Net 1.x, and have stuck with cASP so far...

Summary:
--------------------
When the Command Field consists of a button or text, the control
behaves properly. When an image is used, it does not.
After studying the HTML generated and sent to the client, I have
determined the following:

When TEXT is used, the __doPostBack javascript code is attached.
When BUTTON is used, it does not attach the __do PostBack code.
Instead, it uses the browser's intrinsic behavior to post.

The Bug
-----------------
Now this is where the beast rears it's ugly head...
When IMAGE is used, ASP.Net attaches the __do PostBack code to the
image's OnClick() event, but the image is also defined as an <INPUT>.
So, the browser engine generates a postback as well. This leads to a
double postback to the server.

Workaround
----------------------
A temporary solution is to manually create a Template Field to
encapsulate the image(s), rather then the built in Command Field.
ASP.Net does NOT attach the __doPostBack code to the image's onClick
event when in a Template Field.

Solution
---------------
The proper solution is to alter this behavior in ASP.Net.

And while you're at it, how about the <TABLE> idiosyncrasies of IE?
( cellpadding and cellspacing ) Rather than defining a CSS style for
these, you have to format inline in the page markup. It's been 10
years now... How about it, Bill? ;-)

FWIW,


Greg G.
 
G

GregG

GregG said:
( cellpadding and cellspacing ) Rather than defining a CSS style for
these, you have to format inline in the page markup.

OK - I'm an idiot. I forgot that you have to define the <td> or <th>
properties in CSS for tables... :) It's been a loooong week.
i.e.:

td, th
{
margin: 0;
padding: 0;
}

FWIW,

Greg G.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top