private void RegisterJavaScript()
{
TextBox1.Attributes.Add("OnKeyPress", "doClick('" + Button1.ClientID + "',event)");
}
Code ในส่วนนี้ต้องเรียกใช้ในส่วนของ PageLoad เพื่อกำหนด Attributes ให้กับ TextBox ทุกครั้งที่มีการโหลด Page ครั้ง
แรก จากนั้นให้เขียน Javascript เพื่อเรียกใช้งาน function ที่กำหนดไว้ในตอนแรก ตาม Code นี้
<script type="text/javascript">
function doClick(buttonName,e)
{
var key;
if(window.event)
key = window.event.keyCode; //IE
else
key = e.which; //firefox
if (key == 13)
{
//Get the button the user wants to have clicked
var btn = document.getElementById(buttonName);
if (btn != null)
{ //If we find the button click it
btn.click();
event.keyCode = 0
}
}
}
</script>
ไม่มีความคิดเห็น:
แสดงความคิดเห็น