Triggering other events after losing focus on an ASP. NET TextBox control

Source: Internet
Author: User

Author : CC Abba

2015-2-02

here today, I want to share with you how to deal with ASP . NET TextBox The problem of triggering other events after the control loses focus, here is a summary for reference. Interested students, you can explore and study together, or skip it.

1. First clarify the problem, theASP. NET 2.0 server control has no onBlur. So our first approach is to use a

OnTextChanged to handle it.
One thing to note is that the Txtven AutoPostBack to be set to true.
<asp:textbox id="Txtven"runat="Server"Width="80px"class="TextBox"
Ontextchanged="txtven_textchanged"autopostback="true"></asp:TextBox>

PublicvoidTxtven_textchanged (Objectsender, EventArgs e)
{
stringStrSQL2 ="SELECT * from P_ven WHERE ven= '"+ Txtven.text +"'";
DataSet ds2 = DS (strSQL2,"Sys");
if(DS2 = =NULL|| Ds2. tables[0]. Rows.Count = =0)
{
}
Else
{
//Bring out coins
setSelectedIndex (Ddlcurr, DS2. tables[0]. rows[0]["Currency"]. ToString ());
chkhas_sure.checked = Convert.toboolean ((ds2. tables[0]. rows[0]["has_sure"]). ToString ());
}

        }

Don't think it's done: you'll find that you're not going to be able to enter a background event that you define.

ontextchanged This is how it is, the text changes, not immediately triggered events, need something to trigger the page update, it will play a role

then you have to in the page's Load event, add the following:      

textbox1 . attributes[ " onblur " ] = clientscript.getpostbackeventreference (Control 1,  null );

Then when textbox triggers a control when it loses focus 1 the event.

Control1events can be written at will. when written as:textboxof the Changeevent, just intextboxWhen you lose focus, Executiontextboxof the Changeevent.

so that's quite into the introduction of onblur event. I add the following code to the program:

txtven.attributes["onblur"] = clientscript.getpostbackeventreference ( Txtven, null);

2.

below we use ajax+textchanged Events to deal with.

Subsequent additions

The second part of the following is the solution I used in the program

Welcome to join the technology sharing group , please stay . QQ number

Triggering other events after losing focus on an ASP. NET TextBox control

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.