B
Burak Kadirbeyoglu
Dear Developers,
I have a simple question. There's a textbox and an imagebutton on my page.
When I focus on the textbox and hit enter, the imagebutton is being clicked.
However, when I click somewher else on the page and hit enter, the
imagebutton gets clicked again. How can I unfocus the imagebutton?
The script I'm implementing is given below.
Thanks in advance,
Burak
<script language="JavaScript" type="text/javascript">
<!--
function clickButton(strID) {
var pButton = document.getElementById(strID);
if (event && event.which) {
if (event.which == 13) {
pButton.click();
return false;
}
} else if (window.event && window.event.keyCode) {
if (event.keyCode == 13) {
event.returnValue = false;
event.cancel = true;
pButton.click();
return false;
}
}
}
function Buttonclick(strID) {
var textBox = document.getElementById(strID);
if(textBox.value == "")
{
alert('Please enter keyword(s)...');
return false;
}
}
// -->
</script>
private const string OnKeyPressFormatString = "return(clickButton('{0}'));";
private const string OnClickFormatString = "return(Buttonclick('{0}'));";
SearchTextBox.Attributes.Add("onKeyPress",
String.Format(OnKeyPressFormatString, buttonClientID));
SearchImageButton.Attributes.Add("onClick",String.Format(OnClickFormatString,textBoxID));
SearchButton.Attributes.Add("onClick",String.Format(OnClickFormatString,textBoxID));
I have a simple question. There's a textbox and an imagebutton on my page.
When I focus on the textbox and hit enter, the imagebutton is being clicked.
However, when I click somewher else on the page and hit enter, the
imagebutton gets clicked again. How can I unfocus the imagebutton?
The script I'm implementing is given below.
Thanks in advance,
Burak
<script language="JavaScript" type="text/javascript">
<!--
function clickButton(strID) {
var pButton = document.getElementById(strID);
if (event && event.which) {
if (event.which == 13) {
pButton.click();
return false;
}
} else if (window.event && window.event.keyCode) {
if (event.keyCode == 13) {
event.returnValue = false;
event.cancel = true;
pButton.click();
return false;
}
}
}
function Buttonclick(strID) {
var textBox = document.getElementById(strID);
if(textBox.value == "")
{
alert('Please enter keyword(s)...');
return false;
}
}
// -->
</script>
private const string OnKeyPressFormatString = "return(clickButton('{0}'));";
private const string OnClickFormatString = "return(Buttonclick('{0}'));";
SearchTextBox.Attributes.Add("onKeyPress",
String.Format(OnKeyPressFormatString, buttonClientID));
SearchImageButton.Attributes.Add("onClick",String.Format(OnClickFormatString,textBoxID));
SearchButton.Attributes.Add("onClick",String.Format(OnClickFormatString,textBoxID));