To solve this problem, you must use onblur. The following code is not a project implementation code, but a simulation of the same function.
Copy codeThe Code is as follows:
<! -- The Ajax implementation page does not flash and is always used by Insus. NET. -->
<Asp: ScriptManager ID = "ScriptManager1" runat = "server">
</Asp: ScriptManager>
<Asp: UpdatePanel ID = "UpdatePanel1" runat = "server">
<ContentTemplate>
<Div>
<! -- Place a TextBox for the user to input Data -->
<Asp: TextBox ID = "TextBox1" runat = "server"> </asp: TextBox>
<! -- Place a LinkButton and submit data -->
<Asp: LinkButton ID = "LinkButton1" runat = "server" Text = "Submit" OnClick = "linkbutton#click"> </asp: LinkButton>
</Div>
</ContentTemplate>
</Asp: UpdatePanel>
. Aspx. cs:
Copy codeThe 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.
Copy codeThe 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.