Simulating an 'Insert' button click-event in asp.net listview control
One of my webpages has an asp.net ListView control, with an insertitem template defined. I would like to allow the users of the page to enter data in a text field in the insertitem template, press the enter key, and trigger the insert event (which normally happens when you click开发者_高级运维 the 'insert' button). Can someone please tell me what I need to do for this? I've tried simulating the button click event in javascript, but that doesn't seem to be working.
Thanks
You could hide the button with CSS(display:none) and the on the ENTER make jQuery press it.
The new(asp.net 3.5) defaultbutton attribute can be used with or control. What button will be "clicked" depends of where actually cursor is and what button is chosen as a default button for form or a panel.
<form defaultbutton="button1" runat="server">
<asp:textbox id="textbox1" runat="server"/>
<asp:textbox id="textbox2" runat="server"/>
<asp:button id="button1" text="Button1" runat="server"/>
<asp:panel defaultbutton="button2" runat="server">
<asp:textbox id="textbox3" runat="server"/>
<asp:button id="button2" runat="server"/>
</asp:panel>
</form>
You could use it to trigger your defaultbutton(insert) when you place the controls in InsertItemtemplate inside of a Panel.
精彩评论