Textbox.Text has incorrect value in codebehind

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

    Posted 20 Jul 2013 Link to this post

    Hi, I have a page with several textboxes and comboboxes which all seem to work fine. The issue I have is with one textbox tb_Service and a combobox cmb_Service. What I have is tb_Service is a readonly textbox with a button (but_Modify). When the button is clicked a div is made visible revealing cmb_Services and two buttons to add or delete services. So when the user clicks modify, they select a service from the combobox and click add or delete buttons. These buttons have clientside java which will add or delete the service from tb_Services.
    The code for the add is...
    function butServiceAddClick() {
                var ServiceSelected = $('#cmbx_Service').val().toUpperCase();
                if (ServiceSelected == "PLEASE SELECT...") {
                    //No Service selected so do nothing and exit
                    return true;
                } else {
                    var tb = $('#tb_Services');
                    var oldvalue = tb.val().toUpperCase();
                    var ServiceList = oldvalue + ";";
                    if (/ServiceSelected + ";"/i.test(ServiceList)) {
                        //The selected Service is already in the list
                        //Do nothing and exit
                        return true;
                    } else {
                        var newtext = "";
                        if (ServiceList == ";") {
                            newtext = ServiceSelected;
                        } else {
                            newtext = ServiceList + " " + ServiceSelected;
                        registerChange(tb, oldvalue, newtext);

    The code for deleting is similar and both codes work fine. In a test I added two sevices and ended up with tb_Services displaying SERVICE A; SERVICE B

    I have another button which does a save. This is done in the code behind. When I look at what tb_Services.Text equates to at a breakpoint it is an empty string which is its value when the page was first populated. If I go to a record which already has a Service and add another the textbox displays correctly but once again when I click the save button and check the value of tb_Services is only has the original service and not the one I added. What am I doing wrong?
  2. Vasil
    Vasil avatar
    1604 posts

    Posted 24 Jul 2013 Link to this post

    Hi Mych,

    If you use RadTextBox you have to use it's client side API to get the real value.

    For example: var value = $find("tb_Services").get_value();
    If you want to get the text directly from the input, you can still do this, but it will work the same as with regular Asp:TextBox. So you can test your project with Asp:TextBox to see if the problem is in the RadTextBox or in something else.

    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 the blog feed now.
Back to Top