We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

[Solved] Having trouble programatically setting the text in a TextBox

Thread ID:

Created:

Updated:

Platform:

Replies:

144999 May 31,2019 01:42 PM UTC Jun 3,2019 07:04 AM UTC ASP.NET MVC - EJ 2 3
loading
Tags: Textbox
Andrew
Asked On May 31, 2019 01:42 PM UTC

Hello,

Below is a portion of some code I'm using to help learn how to use the syncfusion controls. It creates a testbox and a button and each time the button is pressed it increments a counter and displays its value in the button caption and in the textbox value. It displays the text in the button caption correctly, but the textbox doesn't seem to get updated.

Using chrome and looking at the page source, the textbox value is being updated but its not being updated on the screen.

Am I missing something ?

<ejs-textbox id="play" placeholder="Play Stuff" value="@ViewBag.Play" enablePersistence="false" multiline="false"></ejs-textbox>
<ejs-button id="myButton" content="Press Me Now !" onClick="Pressed();"></ejs-button>

<script>
    var gbl = 1;
    function Pressed() {
        $.ajax({
            url: '@Url.Action("Zap")',
            dataType: "json",
            type: "POST",
            success: function (data) {
                gbl++;
                var play = $("#play");
                play.attr("value", gbl.toString());
                play.text("dddddd");

                var but = $("#MyButton");
                but.text(gbl.toString());
            }
        });
    }

</script>


Andrew
Replied On May 31, 2019 02:14 PM UTC

I seem to have stumbled on a solution.

If I remove the 

value="@ViewBag.Play"

then the script is able to update the value.

But if I then enter text into the field, it's no longer able to update the value. Not sure what I'm doing wrong here.

A more complete example is in the attachment (I couldnt figure out how to escape the sample and it kept getting truncated when I pasted it in).


Attachment: sample_ca627274.zip

Andrew
Replied On June 1, 2019 12:37 PM UTC

I found my problem. I was trying with text and html in the jqurey portion and I should have been using val

Prince Oliver [Syncfusion]
Replied On June 3, 2019 07:04 AM UTC

Hi Andrew, 

Greetings from Syncfusion support. 

Using the value property in the control that is accessible via the instance of control, you can programmatically set the text in a TextBox. Please refer to the following code. 

<script> 
    var gbl = 1; 
    function Save() { 
        $.ajax({ 
            url: '@Url.Action("Zap")', 
            dataType: "json", 
            type: "POST", 
            success: function (data) { 
                gbl++; 
                var desc = document.getElementById("description").ej2_instances[0]; 
                desc.value = gbl; // Use this instead of the below code 
                // desc.attr("value", gbl.toString()); 
            } 
        }); 
    } 
</script> 

Let us know if you need any further assistance on this. 

Regards, 
Prince 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon