How do disable button selection on a page.

L

Lily

Hi there,
I have several buttons and one datagrid on a page.

Whenever I click on the page anywhere, one of the buttons is selected
(without actually been clicked on), now if I press "Enter" key, the
button's click event got called.

This is a major problem for me!!

I guess this is a feature of ASP.NET. But how could I disable it???
Thanks ahead.
 
C

Curt_C [MVP]

are you trying to stop the button click even from happening or the page
posting back?
 
K

KatB

Lily, I ran into this problem a lot when I first started aspx pages. If
I had buttons and/or text boxes with autopostback = true (when Enter key
is hit), it was hit or miss what event actually fired.

This turned out to be tied to the ORDER of the controls listed in the
HTML. I solved it by creating a tiny button with visible set to false on
the page (in a corner). I always name it btnNeededForEventFiring (so I
would remember what it was for).

The key is then to make sure that this button control comes before any
other event related controls (e.g., buttons or text boxes) in your HTML.

Example:

<asp:button id="btnNeededForEventFiring" style="Z-INDEX: 126; LEFT: 8px;
POSITION: absolute; TOP: 8px" runat="server" Width="1px"
BackColor="Transparent" BorderColor="Transparent" Height="1px"
ForeColor="Transparent"></asp:button>

Hope this helps.
Kat
 

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

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top