Implementation Code for manually submitting data when the object loses focus

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.