Regarding TextBox

Last post 10-08-2008 5:10 AM by Shengqing Yang - MSFT. 14 replies.

Sort Posts:

  • Regarding TextBox

    10-04-2008, 6:47 AM

    Hi,

    I am having a textbox.. I have set its autopostback property as true and have done the proper coding on its textchanged event

    Now My Concerns Are

    1. this event fires when my focus  leaves the textbox.

    2. I want to call the same piece of code of c# which i have done on textchanged event while user changes the text of the text box.. i.e. as user tpes the code should be called..

     

    Please Help

     

    Regards,Meetu Choudhary
    Microsoft MVP-ASP/ASP.NET

    MsDnM || My Forums || My Blog
  • Re: Regarding TextBox

    10-05-2008, 6:27 PM
    • All-Star
      36,316 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 12:51 PM
    • Lincoln, England
    • Posts 5,847

    For number two you should just create a separate function in your code behind and then call that from both areas (text changed and lost focus).

  • Re: Regarding TextBox

    10-05-2008, 8:20 PM
    • All-Star
      98,112 point All-Star
    • mbanavige
    • Member since 11-06-2003, 8:29 AM
    • New England, USA
    • Posts 10,347
    • Moderator
      TrustedFriends-MVPs

    The TextChanged  event is not raised as the user types in the textbox.  it is raised only after the entire page has been posted back to the server and only if the textbox was updated.

    Meetu Choudhary:
    1. this event fires when my focus  leaves the textbox.

    no.  when the textbox loses focus, this is a client side event.  you'd need to use javascript to detect this.

    Meetu Choudhary:
    2. I want to call the same piece of code of c# which i have done on textchanged event while user changes the text of the text box.. i.e. as user tpes the code should be called..

    when the user is typing, you can capture the keystrokes using javascript.  these keystroke do not raise events at the server though.

     

     

    Mike Banavige
    ~~~~~~~~~~~~
    Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
  • Re: Regarding TextBox

    10-05-2008, 11:36 PM

    but what if i want to fetch data from the database at every keystorke

     

    Regards,Meetu Choudhary
    Microsoft MVP-ASP/ASP.NET

    MsDnM || My Forums || My Blog
  • Re: Regarding TextBox

    10-06-2008, 12:19 AM
    • All-Star
      17,471 point All-Star
    • imran_ku07
    • Member since 06-04-2008, 1:21 PM
    • KARACHI, PAKISTAN
    • Posts 3,191

    You can use web service to call webservice in java script function.

  • Re: Regarding TextBox

    10-06-2008, 4:52 AM
    • All-Star
      36,316 point All-Star
    • rtpHarry
    • Member since 10-01-2006, 12:51 PM
    • Lincoln, England
    • Posts 5,847
  • Re: Regarding TextBox

    10-07-2008, 12:24 AM

    rtpHarry:
     

     

    I dont want to use this control i have some my specifications

    so i have to  make control accordingly

    Regards,Meetu Choudhary
    Microsoft MVP-ASP/ASP.NET

    MsDnM || My Forums || My Blog
  • Re: Regarding TextBox

    10-08-2008, 12:03 AM

    Meetu Choudhary:

    but what if i want to fetch data from the database at every keystorke

    Hi Meetu Choudhary,

    I suggest you have a try on TextBox's AutoCompleteType Property.

    You can refer to this link for more information: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.autocompletetype.aspx

    Best Regards,
    Shengqing Yang

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
  • Re: Regarding TextBox

    10-08-2008, 12:13 AM
    Answer

    Hi Meetu Choudhary,

    Here is another demo I worked for you just now.

    It uses a Button whose display is "none" to call the function in the Code-Behind and when the users press in the TextBox, a JavaScript funtion will fired to click the Button. 

    <script type="text/javascript">
        function callsub() {
            document.getElementById("Hidden1").value = document.getElementById("TextBox1").value
            document.getElementById("Button1").click();
        }
        function moveindex() {
            var rng = document.selection.createRange();
            rng.moveStart("character", 200);
            rng.select();
        }     
    </script>
    And also, we need a Hidden field to save the value in the TextBox. 
    <asp:TextBox ID="TextBox1" runat="server" onkeyup="callsub()" onfocus="moveindex()"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" style="display:none" />
    <input id="Hidden1" type="hidden" runat="server" />
    Just for the Text, I make the Button to write the current time on the page. 
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Write(Now)
        TextBox1.Focus()
        TextBox1.Text = Hidden1.Value
    
    End Sub

    You can write your own code in the Button1_Click event handler.

    Best Regards,
    Shengqing Yang

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
  • Re: Regarding TextBox

    10-08-2008, 2:41 AM

     

    Thank you very much for the code

    but coude you please explain me the  utility of the following piece of code

    Shengqing Yang - MSFT:


        function moveindex() {
            var rng = document.selection.createRange();
            rng.moveStart("character", 200);
            rng.select();
        }     
    

     

     

     

    Regards,Meetu Choudhary
    Microsoft MVP-ASP/ASP.NET

    MsDnM || My Forums || My Blog
  • Re: Regarding TextBox

    10-08-2008, 2:48 AM
    Answer

    Meetu Choudhary:

    Thank you very much for the code

    but coude you please explain me the  utility of the following piece of code

    Hi Meetu Choudhary,

    When everytime the TextBox gets focus, the cursor in the TextBox will always be before the first character.

    This piece of code can let the cursor locate after the last character.

    Best Regards,
    Shengqing Yang

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
  • Re: Regarding TextBox

    10-08-2008, 2:55 AM

    Shengqing Yang - MSFT:

    Meetu Choudhary:

    Thank you very much for the code

    but coude you please explain me the  utility of the following piece of code

    Hi Meetu Choudhary,

    When everytime the TextBox gets focus, the cursor in the TextBox will always be before the first character.

    This piece of code can let the cursor locate after the last character.

    Best Regards,
    Shengqing Yang

     

    Thank You Sir Thank You Very Much

    Regards,Meetu Choudhary
    Microsoft MVP-ASP/ASP.NET

    MsDnM || My Forums || My Blog
  • Re: Regarding TextBox

    10-08-2008, 2:56 AM

    Glad to be helpfulSmile

    Best Regards,
    Shengqing Yang

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
  • Re: Regarding TextBox

    10-08-2008, 4:47 AM

     Sir i Tried a lot to understand what each line of code is performing and how but i was not able to understand could you please explain the worth and purpose of each line of the following code given by you

     


    function moveindex() {
    var rng = document.selection.createRange();
    rng.moveStart("character", 200);
    rng.select();
    }

     


    Regards,Meetu Choudhary
    Microsoft MVP-ASP/ASP.NET

    MsDnM || My Forums || My Blog
  • Re: Regarding TextBox

    10-08-2008, 5:10 AM
    Answer

    Hi,

    Here is a very detail reference you can have a look: http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html

    And also go through the article TextArea Cursor Position with JavaScript @ http://weblogs.asp.net/skillet/archive/2005/03/24/395838.aspx

    I think these will be much helpful for you to understand the code.

    Best Regards,
    Shengqing Yang

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread : )
Page 1 of 1 (15 items)