RadTextBox ClientEvents OnKeyPress

3 posts, 0 answers
  1. Evgeniy
    Evgeniy avatar
    11 posts
    Member since:
    Mar 2012

    Posted 10 Aug 2012 Link to this post

    Good day.
    I try use Client Side of RadTextBox. I need take text from one radtextbox, do changes and set new text into the second radtextbox during user press any key in the first radtextbox.
    But behavior is little strange. I use get_value and set_value methods to get and set text from/into radtextbox.
    But first, I can't take full text from textbox (last symbol is always missing)
    Second, set_value doesn't always update text into radtextbox.
    Third, it causes validation error.

    Could you please advise how I can make it?

    Thanks.

    P.S. I can't attach zip file, so I've inserted my code below

    <telerik:RadCodeBlock ID="dfg" runat="server">
        <script type="text/javascript">
            function KeyPress(s, e) {
                var v = s.get_value();
                var l = v.replace(',','');
                var ctrl = $find("<%=txtSecond.ClientID %>");
                ctrl.set_value(l);
            }
        </script>
    </telerik:RadCodeBlock>
    <div>
        Enter some text here <telerik:RadTextBox ID="txtFirst" runat="server" EmptyMessage="Message">
            <ClientEvents OnKeyPress="KeyPress" />
        </telerik:RadTextBox>
        <asp:RequiredFieldValidator ID="wer" runat="server" ControlToValidate="txtFirst" ErrorMessage="*"
            ForeColor="Red" ValidationGroup="gr" SetFocusOnError="true"></asp:RequiredFieldValidator>
        <br /><br />
        Enter some text here <telerik:RadTextBox ID="txtSecond" runat="server" EmptyMessage="Message">
        </telerik:RadTextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtSecond" ErrorMessage="*"
            ForeColor="Red" ValidationGroup="gr" SetFocusOnError="true"></asp:RequiredFieldValidator>
        <br /><br />
         
        <telerik:RadButton ID="btnPostBack" runat="server" Text="Postback" ValidationGroup="gr"></telerik:RadButton>
    </div>
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 15 Aug 2012 Link to this post

    Hello Evgeniy,

    Please note that the RadTextBox updated value on the KeyDown or KeyPress event is not available via the standard browser and Javascript methods as it is still not set to the input itself. You could set a small timeout for getting the correct value or use OnValueChanging event.

    All the best,
    Maria Ilieva
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Evgeniy
    Evgeniy avatar
    11 posts
    Member since:
    Mar 2012

    Posted 16 Aug 2012 Link to this post

    Thank you for reply.
    Using base javascipt code resolve my problem

    <telerik:RadCodeBlock ID="dfg" runat="server">
        <script type="text/javascript">
            function KeyPress() {
                var v = document.getElementById('<%=txtFirst.ClientID %>').value;
                var l = v.replace(',','');
                var ctrl = $find("<%=txtSecond.ClientID %>");
                ctrl.set_value(l);
            }
        </script>
    </telerik:RadCodeBlock>
    <div>
        Enter some text here <telerik:RadTextBox ID="txtFirst" runat="server" EmptyMessage="Message" onkeyup="KeyPress();>
        </telerik:RadTextBox>
        <asp:RequiredFieldValidator ID="wer" runat="server" ControlToValidate="txtFirst" ErrorMessage="*"
            ForeColor="Red" ValidationGroup="gr" SetFocusOnError="true"></asp:RequiredFieldValidator>
        <br /><br />
        Enter some text here <telerik:RadTextBox ID="txtSecond" runat="server" EmptyMessage="Message">
        </telerik:RadTextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtSecond" ErrorMessage="*"
            ForeColor="Red" ValidationGroup="gr" SetFocusOnError="true"></asp:RequiredFieldValidator>
        <br /><br />
          
        <telerik:RadButton ID="btnPostBack" runat="server" Text="Postback" ValidationGroup="gr"></telerik:RadButton>
    </div>
Back to Top