Rad Input Box does not retain client-side set values

3 posts, 0 answers
  1. Mych
    Mych avatar
    18 posts
    Member since:
    Sep 2012

    Posted 15 Oct 2013 Link to this post

    I have several Rad Textboxes with client side scripts attached to ClientEvent OnBlur. This script does two things checks to see that the box has text and changed the case of the text to Proper Case. 

    My mark-up for the Textbox is.... 
    <telerik:RadTextBox ID="RadTextBox1" runat="server" EmptyMessage="Please Enter" SelectionOnFocus="SelectAll" Width="100%">
        <ClientEvents OnBlur="function(sender,args){checkCap(sender, args, 'lb_RadTextBox1');}" />
    </telerik:RadTextBox>
    <asp:Label ID="lb_RadTextBox1" runat="server" CssClass="error"></asp:Label>


    My hideError function is
    function checkCap(sender, args, label) {
     
        var tb = $('#' + sender._clientID);
        var lb = document.getElementById(label);
     
       if ($.trim(tb[0].value) == "") {
           lb.innerHTML = " Mandatory Field";
       } else {
           var pc = pCase($.trim(tb[0].value));
           tb[0].value = pc;
             lb.innerHTML = "";
       }
    }

    The pCase function just goes through the text and capitalises only certain characters. This functions correctly and once a textbox has lost focus either a lable is populated with Mandatory Field if the box is empty or the text is properly capitalised if it contains any text.

    My problem is on the server-side if I try to use the value of RadTextBox1.Text I get the text as it was originally typed not the capitalised version that is displayed. What am I doing wrong?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Oct 2013 Link to this post

    Hi Mych,

    Setting the RadTextBox value using its set_value() client method should persist it after subsequent submits. Please have a look into the following code snippet that I tried.

    ASPX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server" EmptyMessage="Please Enter" SelectionOnFocus="SelectAll"
        Width="100%">
        <ClientEvents OnBlur="function(sender,args){checkCap(sender, args, 'lb_RadTextBox1');}" />
    </telerik:RadTextBox>
    <asp:Label ID="lb_RadTextBox1" runat="server" CssClass="error"></asp:Label>
    <br />
    <asp:Button ID="Button1" runat="server" Text="GetValue" OnClick="Button1_Click" />

    JavaScript:
    <script type="text/javascript">
        function checkCap(sender, args, label) {
            debugger
            var tb = $('#' + sender._clientID);
            var lb = document.getElementById(label);
            if ($.trim(tb[0].value) == "") {
                lb.innerHTML = " Mandatory Field";
            } else {
                var pc = pCase($.trim(tb[0].value));
                sender.set_value(pc);
                lb.innerHTML = "";
            }
        }
        function pCase(value) {
            value = value.toUpperCase();
            return value;
        }
    </script>

    C#:
    protected void Button1_Click(object sender, EventArgs e)
    {
        string value = RadTextBox1.Text;
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mych
    Mych avatar
    18 posts
    Member since:
    Sep 2012

    Posted 16 Oct 2013 Link to this post

    Shinu,

    Thanks... That did the trick... works perfectly.

    Mych
Back to Top