Hello,
In my page there is a text box where user's can search for different organizations in the company. I want them to be able to hit enter and have the SearchButton's onclick event to be fired. Currently when they hit enter, the first button in the code has its onclick event fired, which is not what I want to happen.
When I enter text into the textbox and press enter, the page fails with a javascript error: "Microsoft JScript runtime error: 'null' is null or not an object", and the following code is highlighted: Button1.click(); Also, when I hover over Button1, the little window that displays the value shows null. I'm not sure why this control is null. Any ideas on what could be causing this behavior would be appreciated.
Here is the code I am using to make this happen:
In my page there is a text box where user's can search for different organizations in the company. I want them to be able to hit enter and have the SearchButton's onclick event to be fired. Currently when they hit enter, the first button in the code has its onclick event fired, which is not what I want to happen.
When I enter text into the textbox and press enter, the page fails with a javascript error: "Microsoft JScript runtime error: 'null' is null or not an object", and the following code is highlighted: Button1.click(); Also, when I hover over Button1, the little window that displays the value shows null. I'm not sure why this control is null. Any ideas on what could be causing this behavior would be appreciated.
Here is the code I am using to make this happen:
| protected void Page_Load(object sender, EventArgs e) |
| { |
| this.TextBox1.Attributes.Add("onkeypress","button_click()"); |
| } |
| function button_click() { |
| if (window.event.keyCode == 13) { |
| var Button1 = $find("<%= Button1.ClientID %>"); |
| Button1.click(); |
| window.event.cancel = true; |
| } |
| } |
| <asp:Button ID="Button1" runat="server" |
| Text="Search" Width="70px" onclick="Button1_Click" /> |