How to fire Textbox textchanged event while typing in textbox

后端 未结 3 1152
感动是毒
感动是毒 2021-01-25 11:55

In my project i am using Textbox inside updatepanel to display the Receipt number which is not already exist in db table. But the textchanged event on the textbox is no

相关标签:
3条回答
  • 2021-01-25 12:30

    You can create a procedure in serverside and execute it with javascript. The logic used below is simple, create a procedure, add a button and set visibility to false or display: none with css. The procedure is then fired on click of the button, and the click event is being triggered from the javascript. Feel free to ask if you encounter any problem

    vb code

        Public Sub FetchRecord()
    
        'Your Code Here..
    
        End Sub
    
    Protected Sub btnView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnView.Click
            FetchRecord()
    End Sub
    

    Javascript

    <script type="text/javascript">
            function Filter() {
                document.getElementById('<%= btnView.ClientID %>').click()
            }
    </script>
    

    0 讨论(0)
  • 2021-01-25 12:31

    Use this, its working fine

    JAVASCRIPT

    function ChangeText() {
                var t1 = document.getElementById('<%= txtArticleTitle.ClientID %>');
                var t2 = document.getElementById('<%= txtPageName.ClientID %>');
    
                t2.value = t1.value;
            }
    

    ASP.NET SOURCE

    Article Title:
     <asp:TextBox ID="txtArticleTitle" runat="server" onkeyup="ChangeText()" Width="600px"></asp:TextBox>
    <br />
    Page Name:
    <asp:TextBox ID="txtPageName" runat="server" Width="600px"></asp:TextBox>
    
    0 讨论(0)
  • 2021-01-25 12:31

    two notes.

    1. Textchanged fires when the text box loses focus. You can use the keyd own or keypress events instead.

    2. Calling the server every time a user presses a key is not recommended. Consider using a timeout so you call the server only when the user finished typing (350 milliseconds is the standard I think) or pre load a list from the server and filter it client side.

    P.S.

    Do not use ASP.Net ajax... Just saying.

    0 讨论(0)
提交回复
热议问题