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