C # Add a focus loss event for textbox add in the load event on the page:
Textbox1.attributes ["onblur"] = clientscript. getpostbackeventreference (Control 1, null );
When the textbox loses focus, the control 1 event is triggered.
The event of Control 1 can be written at will. When it is written as a textbox change event, the textbox change event is executed when the textbox loses focus.
// *. Aspx
<% @ 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> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: Label id = "lblmessage" runat = "server"> </ASP: Label> <br/>
<Asp: textbox id = "textbox1" runat = "server"> </ASP: textbox>
<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "I am hidden" style = "display: none"/>
</Form>
</Body>
</Html>
// *. CS
Using system;
Using system. Data;
Using system. configuration;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Textbox1.attributes ["onblur"] = clientscript. getpostbackeventreference (button1, null );
}
}
Protected void button#click (Object sender, eventargs E)
{
Lblmessage. Text = "text box out of focus ";
}
}