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

Disabled radtextbox - Value set via JS lost upon submit

11 Answers 364 Views
Input
This is a migrated thread and some comments may be shown as answers.
Serhat Gülmez
Top achievements
Rank 1
Serhat Gülmez asked on 07 Mar 2012, 03:33 PM
Hello,

I have a disabled radtextbox on my page and set its value at client site using JS API, set_value(), function. The value is not available through .Text property of the control at server side.

This used to work before, though we switched to .NET 4.0 version of the library and that may have something to do with this.

My ASPX is:
<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
    CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">   
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <telerik:RadTextBox runat="server" ID ="txtTelerik" Enabled="false" Width="400" ></telerik:RadTextBox>
    <asp:Button runat="server" ID="btnPost" Text="btnPost" />
     
    <br /><br /><asp:Label runat="server" ID="lblMessage"></asp:Label>
 
     
    <telerik:RadScriptBlock ID="radScriptBlock1" runat="server">
        <script language="javascript" type="text/javascript">
            function Init()
            {
                var ctrl = $find("<%=txtTelerik.ClientID %>");
                if (ctrl != null)
                    ctrl.set_value("Value lost upon postback");
            }
 
            Sys.Application.add_load(Init);
        </script>
    </telerik:RadScriptBlock>
</asp:Content>

Code Behind is:
Public Class _Default
    Inherits System.Web.UI.Page
 
    Private Sub btnPost_Click(sender As Object, e As System.EventArgs) Handles btnPost.Click
        lblMessage.Text = " Value after post = [" + txtTelerik.Text + "]"
    End Sub
End Class


Thanks

11 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 08 Mar 2012, 10:56 AM
Hello Abdurrahman,

I am not quite sure about the scenario that you are explaining.

Here is the sample code which I tried.
aspx:
<telerik:RadTextBox runat="server" ID="txtTelerik" Enabled="false" ClientEvents-OnLoad="OnLoad" Width="400">
</telerik:RadTextBox>
<asp:Button runat="server" ID="btnPost" Text="btnPost" OnClick="btnPost_Click" />
 <br />
<asp:Label runat="server" ID="lblMessage"></asp:Label>
<telerik:RadScriptBlock ID="radScriptBlock1" runat="server">
   <script language="javascript" type="text/javascript">
         function Init() {
           var ctrl = $find("<%=txtTelerik.ClientID %>");
               if (ctrl != null)
                  // ctrl.set_value("Value lost upon postback");
            }
      Sys.Application.add_load(Init);
  </script>
 </telerik:RadScriptBlock>
</div>
 </form>
</body>
</html>
<script type="text/javascript">
    function OnLoad(sender, args) //setting the value on OnLoad
     {
        sender.set_value("test");
    }
</script>
C#:
protected void btnPost_Click(object sender, EventArgs e)
   {
       Response.Write(txtTelerik.Text); // got the textBox value as "test"
   }

Please elaborate your scenario if it doesn't help.
Thanks,
shinu.
0
Serhat Gülmez
Top achievements
Rank 1
answered on 08 Mar 2012, 11:20 AM
Hi Shinu,

Your version of the aspx too does not work with the 2012.1.228 and 2012.1.306 versions of the Telerik ASP.NET AJAX library. Because of a bug in the 2012.1 215 version we had to switch to the nightly build, so not sure if the project works with 1.215 version.

However 2011.3.1305 version works fine with the sample in question.

Thanks
0
Vasil
Telerik team
answered on 09 Mar 2012, 10:43 AM
Hi Abdurrahman,

The behavior in the new version is actually the right one in this case. As Q1 2012 the RadInput uses its new rendering by default with one input for both validation and editing.

According to the HTML specification:

When set, the disabled attribute has the following effects on an element:
A successful control is "valid" for submission. Therefore you should not expect to get server side value of a control that is disabled.

All the best,
Vasil
the Telerik team
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 their blog feed now.
0
Serhat Gülmez
Top achievements
Rank 1
answered on 09 Mar 2012, 12:30 PM
Hi Vasil,

I guess this change should be posted as a Breaking Change in the release notes, as I'm sure it would effect a great many of your customers.

As for our case, we would need to override the set_value() JS function of radtextbox so that we can store the values in a hidden control or so. Is it possible to somehow append custom JS calls into the set_value function?

Thanks
0
Vasil
Telerik team
answered on 13 Mar 2012, 09:10 AM
Hello,

Thank you for your feedback. In the release notes the single input rendering itself is stated as breaking change. We will try to catch up the documentation in order to describe scenarios in which the behavior can differ.

You could override the Telerik.Web.UI.RadInputControl.prototype._setHiddenValue function, which is internally used when changing the value (in the original input rendering this function was used when set a value the "_text" input)

Telerik.Web.UI.RadInputControl.prototype._setHiddenValue_original = Telerik.Web.UI.RadInputControl.prototype._setHiddenValue;
Telerik.Web.UI.RadInputControl.prototype._setHiddenValue = function (value)
{
  //do your logic here. Then call the original function.
  this._setHiddenValue_original(value);
}

Regards,
Vasil
the Telerik team
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 their blog feed now.
0
Michael
Top achievements
Rank 1
answered on 03 Jan 2013, 12:03 PM
I think this issue needs a fix.  I just spent the last hour trying to figure out why my textbox was losing its value when getting to the code behind, to find out it was a breaking change made by Telerik.  The rest of .NET allows you to get the value or text of a disabled control, i do not see why the RadTextBox should be any different.

Please could this be added to your public bug tracker and a link provided so i can follow it.


Also to add i think you have interpreted that from the spec very poorly.  Just because i access the control does not mean i am assuming it was successful or not successful.  That would surely be down the logic in my code and what i chose to do with it.  My question is, if that interpretation to be believed how are you supposed to disable a control from user input but still access it and still show it on screen?


Edit: i am now using readonly. 

Thanks,
Michael
0
Vasil
Telerik team
answered on 03 Jan 2013, 01:02 PM
Hi Michael,

You could try asp:TextBox (or normal HTML Input element) and will see that it behaves the same way:
<asp:TextBox runat="server" disabled="disabled"></asp:TextBox>

It is not something that we have implemented or misunderstood from the standards, it is the way that the browsers are working.

Kind regards,
Vasil
the Telerik team
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 their blog feed now.
0
Al
Top achievements
Rank 1
Iron
answered on 18 Jan 2013, 12:02 PM
Hi 

Please could you tell me how you chose to solve this.  I find it very frustrating that this has changed, as i used it extensively in my code and after an upgrade it does not work.

I would like to have a visible textbox that is disabled from the user but can be updated by client script.

Many Thanks,

Al
0
Michael
Top achievements
Rank 1
answered on 18 Jan 2013, 12:50 PM
I used the ReadOnly property instead of the Enabled property.  It means the box cant be edited by can still be used. 
0
Al
Top achievements
Rank 1
Iron
answered on 18 Jan 2013, 01:16 PM
Fab thanks that worked.
I will style it with css to to make it look disabled
0
Richy
Top achievements
Rank 1
answered on 16 Jan 2014, 02:33 PM
I wanted to add my thoughts to this topic.

We have recently upgraded from 2011 to 2013. We have used visible disabled textboxes (updated by other input controls) extensively in a lot of our application pages.

After discovering this is a Breaking  Change, I will now have a hell of a lot of re-coding to do.

This is another example of Telerik updating controls "for the better", except not thinking about their existing customer set and how the controls are currently being used.

Please Telerik think about making the controls backwards compatible as much as possible. These changes might seem minor to you, but for Companies they add a lot of overheads to development costs and can result in delayed project deliverables. It is extremely frustrating.
Tags
Input
Asked by
Serhat Gülmez
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Serhat Gülmez
Top achievements
Rank 1
Vasil
Telerik team
Michael
Top achievements
Rank 1
Al
Top achievements
Rank 1
Iron
Richy
Top achievements
Rank 1
Share this question
or