文本框数据输入后自动保存。 [英] Auto save after textbox data input.

查看:706
本文介绍了文本框数据输入后自动保存。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c#asp.net的初学者,试着使用条形码扫描仪创建一个系统。我的问题是我需要按下按钮将数据保存在我们的数据库中。我需要的是在扫描条形码后自动保存数据。



我尝试过:



i am beginner in c# asp.net ill try to create a system using barcode scanner. my problem is i need to press the button to save the data in our database. all i need is to autosave data after scan the barcode.

What I have tried:

private void btn_Save_Click(object sender, EventArgs e)
     {
             Rooming rooming = new Rooming();
             rooming.RowNo = Convert.ToInt32(cmb_RowNo.Text);
             rooming.LineNo = Convert.ToInt32(cmb_LineNo.Text);
             rooming.StackNo = Convert.ToInt32(cmd_StackNo.Text);
             rooming.BoxNo = txt_BoxNo.Text;
             db.roomings.Add(rooming);
             db.SaveChanges();
     }

推荐答案

您正在点击按钮。问题 - 如果你要抓住一个关键的新闻事件(你可以),你怎么知道他们何时停止打字?特别是当你有5个文本框?



你的按钮点击也是一个回发。如果你想在按键上操作,你需要在javascript中处理按键,确定何时有足够的输入来进行保存,然后进行调用以保存它。无论如何,它是2019年,没有人想要在点击保存时处理重新加载整个页面的网站。



因为你是初学者,我强烈建议你永远不要再看你的ASP.NET了。首先看看MVC,我猜,但期望最终为您的数据层编写MVC控制器,并在React或Angular等javascript库中编写您的站点。
You're catching a button click. Question - if you were to catch a key press event (which you can), how would you know when they stopped typing? Especially when you have 5 textboxes?

Your button click is also a postback. If you want to act on a keypress, you need to handle the keypress in javascript, decide when you've got enough input to do a save, and then do a call to save it. It is, in any case, 2019, and no one wants to deal with a website that reloads the entire page when they click save.

As you're a beginner, I recommend strongly never looking at ASP.NET again in your life. Start by looking at MVC, I guess, but expect to eventually write MVC controllers for your data layer, and writing your site in a javascript library like React or Angular.


这篇关于文本框数据输入后自动保存。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆