TextBox text assigned by javascript

5 posts, 0 answers
  1. PAOLO
    PAOLO avatar
    6 posts
    Member since:
    Apr 2012

    Posted 25 Jun 2013 Link to this post

    Good day.
    With the release 2013.2 I assign the value of a tbox with the script:

    $("#RadWindowDataEntryArticolo_C_tboxArticoloCodice_tbox").val(Codice)

    In code behind the text property is blank. After a click in the control, the text property, is what I'm expected.
    What's wrong ?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jun 2013 Link to this post

    Hi PAOLO,

    I am able to replicate this issue in RadControls version 2013.2.611.40 whereas it works fine in 2013.1.417.40 and previous releases. This seems to a bug in the latest version and as you said the value is preserved if the user clicks in the control. As a work around, along with your JS code you try focusing and blurring the RadTextBox so that the value is accessible in the server side. Please check the following code.

    JavaScript:
    $telerik.$('#RadTextBox1').val(Codice).focus().blur();

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. PAOLO
    PAOLO avatar
    6 posts
    Member since:
    Apr 2012

    Posted 25 Jun 2013 Link to this post

    Hi Shinu,
    I've try but is not working.
    The value is correctly visible in the control but until I click on the control it's not in the text codebehind property.

    $("#RadWindowDataEntryArticolo_C_tboxArticoloCodice_tbox").val(Codice).focus().blur();
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Jun 2013 Link to this post

    Hi PAOLO,

    I am able to replicate the issue at my end but the JavaScript code I tried solved the issue and I am able to access the updated text in the code behind. To avoid a click in the RadTextBox, I am giving focus from JS code and I guess it should work. Here is the full code I tried in which after setting the RadTextBox text from JavaScript I am accessing the updated text in server side on a RadButton click and updating an ASP label text.

    ASPX:
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <div>
        <telerik:RadTextBox ID="RadTextBox1" runat="server">
        </telerik:RadTextBox>
        <br />
        <input type="button" value="Set Text from JavaScript" onclick="setText();" />
        <br />
        <telerik:RadButton ID="RadButton1" runat="server" Text="Get Text in C#" OnClick="RadButton1_Click">
        </telerik:RadButton>
        <br />
        <br />
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>

    JavaScript:
    <script type="text/javascript">
        function setText() {
            var Codice = "MyText";
            $telerik.$('#RadTextBox1').val(Codice).focus().blur();
        }
    </script>

    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        Label1.Text = RadTextBox1.Text;
    }

    Thanks,
    Shinu.
  6. PAOLO
    PAOLO avatar
    6 posts
    Member since:
    Apr 2012

    Posted 01 Jul 2013 Link to this post

    Hi Shinu,
    I've try your solution but at my side is not working.
    Another, maybe useful, information for you: my input controls are in a RadWindow control.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017