Invalid Postback

  • Thread starter Thread starter Aric Levin
  • Start date Start date
A

Aric Levin

I have two text boxes and two image buttons on a web form, one coming from a
user control and the other on the form.

When I click each of the buttons, the application performs properly. When I
press enter though, wherever (or in any form), I always get a Postback from
the User Control Image Button. I would like to have an event that when I
press enter on the User Control's Text Box it posts back, and not in other
places (unless specified).

I don't want to use third party controls if possible.

Thanks,

Aric Levin
 
Aric said:
I have two text boxes and two image buttons on a web form, one coming from a
user control and the other on the form.

When I click each of the buttons, the application performs properly. When I
press enter though, wherever (or in any form), I always get a Postback from
the User Control Image Button. I would like to have an event that when I
press enter on the User Control's Text Box it posts back, and not in other
places (unless specified).

I don't want to use third party controls if possible.

Thanks,

Aric Levin

Aric,

Try this code in your page and replace 'myTextBox' with the ID of your
TextBox:

<script type="text/javascript" language="javascript">
<!--
document.onkeypress=
function checkKeyPress(e)
{
var key=document.layers?e.which:document.all?event.keyCode:e.keyCode;
if (key == 13)
{
// Enable the Enter button if one of the submit buttons has focus
if (event.srcElement) // IE
{
if(event.srcElement.name=='myTextBox')
return(true);
else
return(false);
}
else if (event.target) // Netscape
{
if(event.target.name=='myTextBox')
return(true);
else
return(false);
}
else
return(false);
}
}

if (document.layers)
{
document.captureEvents(Event.KEYPRESS);
}

if (! document.all && document.getElementById)
{
document.addEventListener("keypress", checkKeyPress, true);
}
// -->
</script>

Darrell
http://dotnetjunkies.com/WebLog/darrell.norton/
 
Back
Top