Automatically submit data V2 when objects in asp.net lose focus

Source: Internet
Author: User

The. aspx page only pulls one TextBox Control:
Copy codeThe Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Asp: TextBox ID = "TextBox1" runat = "server"> </asp: TextBox>
</Form>
</Body>
</Html>

In the. aspx. cs page, you are preferred to register the OnBlur event for the TextBox in the Page_Init event:
Copy codeThe Code is as follows:
Protected void Page_Init (object sender, EventArgs e)
{
This. TextBox1.Attributes. Add ("onblur", Page. ClientScript. GetPostBackEventReference (this. TextBox1, "OnBlur "));
}

Write an onBlue event to replace the Click Event of the LinkButton:
Copy codeThe Code is as follows:
Private void OnBlurHandle (string ctrl, string args)
{
If (ctrl = this. TextBox1.UniqueID & args = "OnBlur ")
{
// Write and submit it to the database
}
}

Then, in the Page_Load event of the webpage, determine whether IsPostBack is used.
Copy codeThe Code is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
If (IsPostBack)
{
Var ctrl = Request. Params [Page. postEventSourceID];
Var args = Request. Params [Page. postEventArgumentID];
OnBlurHandle (ctrl, args );
}
}

Related Article

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.