Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > how to make imagebutton respond to click but not return key

Reply
Thread Tools

how to make imagebutton respond to click but not return key

 
 
mhylden
Guest
Posts: n/a
 
      09-28-2005
I need to make an imagebutton that is contained in a datagrid respond
only to a mouse click, and not a return key press. I have a user
control on the same page that contains text boxes (HTML controls) and
link buttons (.NET web controls) to handle the return key press as a
search. That part works, but when I do that, I still get a js
confirmation that goes along with the link buttons in the datagrid, as
if one of those had been clicked. Clicking cancel on the confirm
dialog lets the response.redirect command from the search linkbutton
continue on to the search results as expected, but I don't want the
confirm to come up at all. I'd like to take the return key action off
of the image buttons entirely, since the user should pick a specific
row from the grid. I can't just disable the imagebutton though, since
a click still needs to work.

I've tried fiddling with the tab indexes on the different controls to
get it to fire one and not the other, but no luck.

Any help is greatly appreciated.

Mikkel

Code snippets below:
this is the script for the imagebutton confirm, located at the top of
my ASPX page that contains the datagrid:
<script language="javascript">
function ConfirmQuickComplete()
{
return confirm('Are you sure you want to mark this action item as
complete?');
}
</script>
script that checks for the return key press and fires redirect to
search, located at the top of my user control:
function CheckEnter()
{
var e = window.event;

var key = e.keyCode;
var src = e.srcElement;
var srcName = src.id;

if (key == 13)
{
if (srcName == 'txtFindProjHTML')
{
alert(srcName + key);
__doPostBack('QuickPicks1$lbFindProj','');
return false;
}
}
}
LinkButton click event handler, in user control:
private void lbFindProj_Click(object sender, System.EventArgs e)
{

string stxt = Request["txtFindProjHTML"];
Response.Redirect(Request.ApplicationPath +
"/ActionTrack/ProjectList.aspx?projName=" + stxt,true);
}
The imagebutton is a template column in my datagrid, and I set
properties on that in the ItemDataBound event on the grid as follows:
....
ImageButton btn = (ImageButton)(e.Item.Cells[6].Controls[1]);
btn.Attributes.Add("onclick", "return ConfirmQuickComplete();");
btn.Attributes.Add("TabIndex", "0");
....

 
Reply With Quote
 
 
 
 
mhylden
Guest
Posts: n/a
 
      09-28-2005
I figured out a solution, even if it may not be the most graceful one.

I declare a javascript variable outside the keypress function in my
user control like so:
var returnPressed = false;
function CheckEnter()
{
var e = window.event;

var key = e.keyCode;
var src = e.srcElement;
var srcName = src.id;

if (key == 13)
{
returnPressed = true;

if (srcName == 'txtFindProjHTML')
{
<%= Page.GetPostBackEventReference(lbFindProj) %>;
return false;
}
}
}

Then in the click event handler on my link button that should not fire
on a return key press, which is in the main page, I check that
variable:

function ConfirmQuickComplete()
{
if (returnPressed)
{
return false;
}
else
{
return confirm('Are you sure you want to mark this action item as
complete?');
}
}

This allows the return key press to fire the appropriate search in my
user control, but if the button is actually pressed, then the confirm
event fires as it should. The js variable will be set on a lot of
pages containing the user control where I don't really need it, but if
similar problems arise it will be a quick scripting fix.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
how to make imagebutton respond to click but not return key mhylden ASP .Net Web Controls 1 09-28-2005 07:51 PM
raising a Click or Command event on an ImageButton click control James Tsao ASP .Net Web Controls 0 10-25-2004 09:17 PM
How do I make my JDialog's buttons respond to enter key? Paul Tomblin Java 15 10-24-2004 10:30 PM
Replace Tab Key to Return Key (Enter Key) from Web Forms? M P ASP General 1 08-06-2004 08:32 AM



Advertisments