tags:

views:

35

answers:

2

On pressing enter key, I want and image button's click event to get fired. So i have placed the textbox and button inside a panel and given the image button's id in 'DefaultButton' property of the panel. But on pressing enter key, the image button's click event does not get fired. The code is pasted below:

<asp:Panel ID="pnlGlobalSearch" DefaultButton="imgbtnSearch" runat="server">
    <table width="226" border="0" cellpadding="2" cellspacing="2">
    <tr>
        <td width="150" align="right">
            <asp:TextBox ID="txtSearch" CssClass="para1Black" Width="150px" 
                     ValidationGroup="GlobalSearch" runat="server" />
            <cc1:FilteredTextBoxExtender ID="txtSearch_FilteredTextBoxExtender" 
                     runat="server" Enabled="true" TargetControlID="txtSearch" 
                     FilterType="UppercaseLetters,LowercaseLetters,Custom,Numbers" 
                     FilterMode="InvalidChars"
                     InvalidChars="~`!@#$%^&_-+|\?*(){}[]:;,.',"" />
            <cc1:TextBoxWatermarkExtender ID="txtSearch_TextBoxWatermarkExtender" 
                     WatermarkText="Enter text to search." runat="server" 
                     Enabled="true" TargetControlID="txtSearch" />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                     ControlToValidate="txtSearch" ValidationGroup="GlobalSearch"  
                     CssClass="error" Display="None" 
                     ErrorMessage="Please enter text to search."/>                 
            <cc1:ValidatorCalloutExtender ID="RequiredFieldValidator1_ValidatorCalloutExtender" 
                     runat="server" Enabled="true" 
                     TargetControlID="RequiredFieldValidator1"/>
        </td>
        <td width="76">
            <asp:ImageButton ID="imgbtnSearch" ToolTip="Click to search." 
                   ImageUrl="images/search2.jpeg" CausesValidation="true" 
                   Width="22px" Height="22px" ValidationGroup="GlobalSearch" 
                   runat="server" OnClick="imgbtnSearch_Click" />
      </td>
   </tr>
   </table>
</asp:Panel>

Also please provide code for search textbox function present in stack overflow website. On entering text in textbox and pressing enter key, the search function should get executed.

A: 

Try setting ClientIDMode="Static" on the ImageButton (.net 4 only)

geoff
We are using .Net 3.5 only! ClientIDMode="Static" does not work!
banupriya
OK. Try setting the DefaultButton property in code: pnlGlobalSearch = imgbtnSearch.UniqueID - I think it is the generated clientside id that is the problem.
geoff
I tried giving pnlGlobalSearch.DefaultButton = imgbtnSearch.ClientID; as well as pnlGlobalSearch.DefaultButton = imgbtnSearch.UniqueID; but none of them worked out. I also tried giving default button property in the form tag but that too didn't work!
banupriya
A: 

I have done a silly mistake!! On key down event of textbox I have added javascript code to prevent special characters, in that I have allowed the characters which can be typed in the textbox.. In that part i have not given enter key's key code!!! Now the issue is fixed.

banupriya