Disabled radtextbox - Value set via JS lost upon submit

12 posts, 0 answers
  1. Abdurrahman Battal
    Abdurrahman Battal avatar
    20 posts
    Member since:
    Nov 2008

    Posted 07 Mar 2012 Link to this post

    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
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 08 Mar 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Abdurrahman Battal
    Abdurrahman Battal avatar
    20 posts
    Member since:
    Nov 2008

    Posted 08 Mar 2012 Link to this post

    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
  5. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 09 Mar 2012 Link to this post

    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.
  6. Abdurrahman Battal
    Abdurrahman Battal avatar
    20 posts
    Member since:
    Nov 2008

    Posted 09 Mar 2012 Link to this post

    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
  7. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 13 Mar 2012 Link to this post

    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.
  8. Michael
    Michael avatar
    31 posts
    Member since:
    Dec 2011

    Posted 03 Jan 2013 Link to this post

    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
  9. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 03 Jan 2013 Link to this post

    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.
  10. Al
    Al avatar
    18 posts
    Member since:
    Apr 2007

    Posted 18 Jan 2013 Link to this post

    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
  11. Michael
    Michael avatar
    31 posts
    Member since:
    Dec 2011

    Posted 18 Jan 2013 Link to this post

    I used the ReadOnly property instead of the Enabled property.  It means the box cant be edited by can still be used. 
  12. Al
    Al avatar
    18 posts
    Member since:
    Apr 2007

    Posted 18 Jan 2013 Link to this post

    Fab thanks that worked.
    I will style it with css to to make it look disabled
  13. Richy
    Richy avatar
    2 posts
    Member since:
    Jun 2011

    Posted 16 Jan 2014 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017