This is a migrated thread and some comments may be shown as answers.

Rad Input Box does not retain client-side set values

2 Answers 43 Views
Input
This is a migrated thread and some comments may be shown as answers.
Mych
Top achievements
Rank 1
Mych asked on 15 Oct 2013, 02:04 PM
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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 16 Oct 2013, 05:06 AM
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.
0
Mych
Top achievements
Rank 1
answered on 16 Oct 2013, 09:35 AM
Shinu,

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

Mych
Tags
Input
Asked by
Mych
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Mych
Top achievements
Rank 1
Share this question
or