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

Textbox.Text has incorrect value in codebehind

1 Answer 181 Views
Input
This is a migrated thread and some comments may be shown as answers.
Mych
Top achievements
Rank 1
Mych asked on 20 Jul 2013, 11:22 AM
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;
                    }
                    tb.val(newtext);
                    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?

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 24 Jul 2013, 07:50 AM
Hi Mych,

If you use RadTextBox you have to use it's client side API to get the real value.
http://www.telerik.com/help/aspnet-ajax/input-client-side-radtextbox.html

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.

Regards,
Vasil
Telerik
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.
Tags
Input
Asked by
Mych
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or