在asp.net中,如何斷行符號觸發指定按鈕的事件?
假設:
<asp:TextBox id="TextBox1" runat="server" Width="240px"></asp:TextBox> <asp:Button id="ButtonOK" runat="server" BorderWidth="1px" BorderColor="Purple" BorderStyle="Solid" Text="Search Site"></asp:Button> |
解決方案:
在.aspx頁面中添加:
<SCRIPT LANGUAGE="javascript"> function EnterKeyClick(button) { if (event.keyCode == 13) { event.keyCode=9; event.returnValue = false; document.all[button].click(); } } </SCRIPT> |
在Page_Load事件中添加:
TextBox1.Attributes.Add("onkeydown","EnterKeyClick('ButtonOK');"); |
關於DATAGRID資料更改時點2次/行號跟不準/失去焦點/丟失e等一系列問題的解決辦法:首先把資料連線/dataadater等資訊全放到void bindgrid中,其他地方不用if(!ISPOSTBACK),在PAGELOAD的時候只用個
if (!IsPostBack) { BindGrid(); } |
--------------------------------------------------------------
例如:
private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) {BindGrid();} } private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DataGrid1.EditItemIndex = e.Item.ItemIndex; BindGrid(); } private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DataGrid1.EditItemIndex = -1; BindGrid(); } void BindGrid() { oleDbDataAdapter1.Fill(dataSet11); DataGrid1.DataBind(); } |