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

TextBox text assigned by javascript

4 Answers 208 Views
Input
This is a migrated thread and some comments may be shown as answers.
PAOLO
Top achievements
Rank 1
PAOLO asked on 25 Jun 2013, 07:41 AM
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 ?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Jun 2013, 10:16 AM
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.
0
PAOLO
Top achievements
Rank 1
answered on 25 Jun 2013, 02:46 PM
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();
0
Shinu
Top achievements
Rank 2
answered on 26 Jun 2013, 03:51 AM
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.
0
PAOLO
Top achievements
Rank 1
answered on 01 Jul 2013, 12:26 PM
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.

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