• <tfoot id='KyHUh'></tfoot>

      <small id='KyHUh'></small><noframes id='KyHUh'>

    1. <legend id='KyHUh'><style id='KyHUh'><dir id='KyHUh'><q id='KyHUh'></q></dir></style></legend>

          <bdo id='KyHUh'></bdo><ul id='KyHUh'></ul>
        <i id='KyHUh'><tr id='KyHUh'><dt id='KyHUh'><q id='KyHUh'><span id='KyHUh'><b id='KyHUh'><form id='KyHUh'><ins id='KyHUh'></ins><ul id='KyHUh'></ul><sub id='KyHUh'></sub></form><legend id='KyHUh'></legend><bdo id='KyHUh'><pre id='KyHUh'><center id='KyHUh'></center></pre></bdo></b><th id='KyHUh'></th></span></q></dt></tr></i><div id='KyHUh'><tfoot id='KyHUh'></tfoot><dl id='KyHUh'><fieldset id='KyHUh'></fieldset></dl></div>

        ASP.NET TextBox LostFocus 事件

        ASP.NET TextBox LostFocus event(ASP.NET TextBox LostFocus 事件)

                <i id='VM9M7'><tr id='VM9M7'><dt id='VM9M7'><q id='VM9M7'><span id='VM9M7'><b id='VM9M7'><form id='VM9M7'><ins id='VM9M7'></ins><ul id='VM9M7'></ul><sub id='VM9M7'></sub></form><legend id='VM9M7'></legend><bdo id='VM9M7'><pre id='VM9M7'><center id='VM9M7'></center></pre></bdo></b><th id='VM9M7'></th></span></q></dt></tr></i><div id='VM9M7'><tfoot id='VM9M7'></tfoot><dl id='VM9M7'><fieldset id='VM9M7'></fieldset></dl></div>

                <small id='VM9M7'></small><noframes id='VM9M7'>

                <legend id='VM9M7'><style id='VM9M7'><dir id='VM9M7'><q id='VM9M7'></q></dir></style></legend>
                  <tbody id='VM9M7'></tbody>
                  <bdo id='VM9M7'></bdo><ul id='VM9M7'></ul>
                  <tfoot id='VM9M7'></tfoot>
                • 本文介绍了ASP.NET TextBox LostFocus 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当文本框失去焦点时,我需要在服务器端触发代码.

                  I need to trigger code on the server side to be called when a TextBox loses focus.

                  我知道有 onblur 客户端事件,并且没有 LostFocus 事件,那么当我的 TextBox 失去焦点时如何导致回发?

                  I know there is the onblur client side event, and that there is no LostFocus event, so how can I cause a postback to occur when my TextBox loses focus?

                  更新:

                  我找到了一个 blog 似乎为此提供了一个相当不错的解决方案.它涉及向 TextBox 子类添加自定义事件,并在 onblur JavaScript 客户端事件中注册调用服务器端事件的客户端脚本.

                  I have found a blog which seems to give a pretty decent solution to this. It involves adding a custom event to a TextBox subclass, and registering a client script which calls the server-side event in the onblur JavaScript client event.

                  以下是我在VB中的实现:

                  The following is my implementation in VB:

                  Public Class MyTextBox
                      Inherits TextBox
                      Implements IPostBackEventHandler
                  
                      Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
                          MyBase.OnInit(e)
                          If Not Page.ClientScript.IsClientScriptBlockRegistered("OnBlurTextBoxEvent") Then
                              Page.ClientScript.RegisterStartupScript(MyBase.GetType, "OnBlurTextBoxEvent", GetScript, True)
                              Attributes.Add("onblur", "OnBlurred('" & UniqueID & "','')")
                          End If
                      End Sub
                  
                      Public Delegate Sub OnBlurDelegate(ByVal sender As Object, ByVal e As EventArgs)
                  
                      Public Event Blur As OnBlurDelegate
                  
                      Protected Sub OnBlur()
                          RaiseEvent Blur(Me, EventArgs.Empty)
                      End Sub
                  
                      Private Function GetScript() As String
                          Return "function OnBlurred(control, arg)" & vbCrLf & _
                                  "{" & vbCrLf & _
                                  "    __doPostBack(control, arg);" & vbCrLf & _
                                  "}"
                      End Function
                  
                      Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
                          OnBlur()
                      End Sub
                  End Class
                  

                  推荐答案

                  我找到了一个blog 似乎为此提供了一个相当不错的解决方案.它涉及向 TextBox 子类添加自定义事件,并在 onblur JavaScript 客户端事件中注册调用服务器端事件的客户端脚本.

                  I have found a blog which seems to give a pretty decent solution to this. It involves adding a custom event to a TextBox subclass, and registering a client script which calls the server-side event in the onblur JavaScript client event.

                  以下是我在VB中的实现:

                  The following is my implementation in VB:

                  Public Class MyTextBox
                      Inherits TextBox
                      Implements IPostBackEventHandler
                  
                      Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
                          MyBase.OnInit(e)
                          If Not Page.ClientScript.IsClientScriptBlockRegistered("OnBlurTextBoxEvent") Then
                              Page.ClientScript.RegisterStartupScript(MyBase.GetType, "OnBlurTextBoxEvent", GetScript, True)
                              Attributes.Add("onblur", "OnBlurred('" & UniqueID & "','')")
                          End If
                      End Sub
                  
                      Public Delegate Sub OnBlurDelegate(ByVal sender As Object, ByVal e As EventArgs)
                  
                      Public Event Blur As OnBlurDelegate
                  
                      Protected Sub OnBlur()
                          RaiseEvent Blur(Me, EventArgs.Empty)
                      End Sub
                  
                      Private Function GetScript() As String
                          Return "function OnBlurred(control, arg)" & vbCrLf & _
                                  "{" & vbCrLf & _
                                  "    __doPostBack(control, arg);" & vbCrLf & _
                                  "}"
                      End Function
                  
                      Public Sub RaisePostBackEvent(ByVal eventArgument As String) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
                          OnBlur()
                      End Sub
                  End Class
                  

                  这篇关于ASP.NET TextBox LostFocus 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to keep the Text of a Read only TextBox after PostBack()?(PostBack()之后如何保留只读文本框的文本?)
                  Winforms Textbox - Using Ctrl-Backspace to Delete Whole Word(Winforms 文本框 - 使用 Ctrl-Backspace 删除整个单词)
                  Multi-color TextBox C#(多色文本框 C#)
                  How can i set the caret position to a specific index in passwordbox in WPF(如何将插入符号位置设置为 WPF 密码框中的特定索引)
                  C# Numeric Only TextBox Control(C# 纯数字文本框控件)
                  Unicode characters not showing in System.Windows.Forms.TextBox(System.Windows.Forms.TextBox 中未显示 Unicode 字符)
                      <tbody id='dAhg9'></tbody>

                  1. <i id='dAhg9'><tr id='dAhg9'><dt id='dAhg9'><q id='dAhg9'><span id='dAhg9'><b id='dAhg9'><form id='dAhg9'><ins id='dAhg9'></ins><ul id='dAhg9'></ul><sub id='dAhg9'></sub></form><legend id='dAhg9'></legend><bdo id='dAhg9'><pre id='dAhg9'><center id='dAhg9'></center></pre></bdo></b><th id='dAhg9'></th></span></q></dt></tr></i><div id='dAhg9'><tfoot id='dAhg9'></tfoot><dl id='dAhg9'><fieldset id='dAhg9'></fieldset></dl></div>

                    • <small id='dAhg9'></small><noframes id='dAhg9'>

                        <bdo id='dAhg9'></bdo><ul id='dAhg9'></ul>

                        <tfoot id='dAhg9'></tfoot>
                      • <legend id='dAhg9'><style id='dAhg9'><dir id='dAhg9'><q id='dAhg9'></q></dir></style></legend>