Click here to Skip to main content
15,885,758 members
Please Sign up or sign in to vote.
1.27/5 (3 votes)
See more:

My uestion is very simple
I am a programmer of C#
how to fire an event /function from a code behind when i type 6th digit in a textbox ??
Posted
Comments
Sergey Alexandrovich Kryukov 7-Jul-14 1:45am    
Why?
—SA

In the TextBox Textchange event you may call your function
Try this way
protected void TextBox1_TextChanged(object sender , EventArgs e)
{
 if(TextBox1.Text.Length >5) 
 {
  //put your code here
 }
}

thanks
 
Share this answer
 
Comments
Member 8073143 7-Jul-14 1:13am    
thnaks for the solution
but
No this will be fired for very diit enetred into the textbox
I want only this event to be fired when i entered the 6th digit
After looking into your scenario i have prepared one sample for this scenario for you.

I have a asp server textbox control in my page like as below :-
ASP.NET
<asp:textbox id="txtTest" text="" runat="server" autopostback="true" ontextchanged="txtTest_TextChanged" clientidmode="Static"></asp:textbox>


The TextChanged event handler code is as follows in cs code behind for example :-
C#
protected void txtTest_TextChanged(object sender, EventArgs e)
        {
            Response.Write("Success Test");
        }


Now in jQuery on document ready handle the keyup event as below to fire the server side TextChanged event on more than 6 character as below :-
JavaScript
$(function () {
            $("#txtTest").keyup(function (e) {
                if ($("#txtTest").val().length > 6) {
                    __doPostBack('<%# txtTest.ClientID %>', 'OnTextChanged')
                }
            });
        });



Hope this will also be working for you.
Please let me know if any kind of problem you are facing with this code example to get your issue resolve.
 
Share this answer
 
v2
Comments
Member 8073143 7-Jul-14 2:32am    
Thanks for the help.
But the problem which i had in the above your code is that on entering the 6th digit nothing is firing i need to either keep the focus out of the textbox or enter button
But i want as soon as i press enter the 6th digit the event will be fired

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900