On the production line, the input efficiency of the input personnel is improved. before the Barcode gun is purchased, the program needs to be modified, that is, when the mouse cursor leaves the TextBox, the data is automatically submitted to the database to solve this problem, you must use onblur. The following code is not a project implementation code, but a simulation of the same function.
The code is as follows:
. Aspx. cs:
The code is as follows:
Using System;
Using System. Collections. Generic;
Using System. Drawing;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using Insus. NET;
Public partial class _ Default: System. Web. UI. Page {
Protected void Page_Load (object sender, EventArgs e)
{
Data_Binding ();
}
Private void Data_Binding ()
{
}
Protected void linkbutton#click (object sender, EventArgs e)
{
// Write and submit it to the database
// Below is the Demo usage
InsusJsUtility objJs = new InsusJsUtility ();
If (string. IsNullOrEmpty (this. TextBox1.Text. Trim ()))
{
ObjJs. JsAlert ("no data can be submitted. ");
Return;
}
ObjJs. JsAlert ("data submitted:" + this. TextBox1.Text );
}
}
In the Demo above, you still need to click the LinkButton to submit data. To enable the onblur of TextBox to execute the same event of LinkButton, you only need to find "_ doPostBack ()" of LinkButton ()". We can view the source code on the run page:
Add the highlighted yellow code to TextBox as an onblur event. The following code is written to Data_Binding () of. aspx. cs.
The code is as follows:
This. TextBox1.Attributes. Add ("onblur", "_ doPostBack ('linkbutton1 ','')");
Finally, we need to change the Text = "Submit" of the LinkButton to Text = "" to hide the LinkButton.