Can I make a value set in client persist through postback?

5 posts, 0 answers
  1. John
    John avatar
    16 posts
    Member since:
    Jun 2009

    Posted 30 Jul 2009 Link to this post

    Hello,
    I am successfully setting the value of a RadTextBox in javascript using the set_value() method.  However, my values doesn't persist through postback.  Is there  a way to make this happen?  I can be flexible with my approach if need be.

    Thanks!
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 05 Aug 2009 Link to this post

    Hi Mike,

    Setting the RadTextBox value using its set_value() client method should persist it after subsequent submits. I verified that in a local test.

    Can you please post the markup and code-behind of the page in question in this forum thread (using the 'Format Code Block' dialog available from the upper right corner of the forum editor)? Thus I will examine it in detail and will advice you further.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Miao Weibin
    Miao Weibin avatar
    10 posts
    Member since:
    Jul 2008

    Posted 26 Aug 2009 Link to this post

    if ReadOnly is set, the value cannot be persisted when postback.
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Aug 2009 Link to this post

    Hi Miao,

    Try setting the ReadOnly mode by accessing the textboxElement of RadTextBox and setting its readonly property (instead of setting the ReadOnly property of RadTextBox), and see whether it is working as you expected.

    ASPX:
     
    <telerik:RadTextBox runat="server" ID="RadTextBox1"  >  
    <ClientEvents OnLoad="setReadOnly" />  
    </telerik:RadTextBox> 

    JavaScript:
     
    <script type="text/javascript">  
    function setReadOnly()  
    {  
        var TextBox1 = $find("<%= rtxtUserName.ClientID %>");  
        TextBox1._textBoxElement.readOnly = true;  
    </script>  

    -Shinu.
  5. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 26 Aug 2009 Link to this post

    Hello Miao,

    You are right and this behavior is by design - the same is true for the regular MS TextBox instance when it is read-only and you change its value on the client.

    I suppose the reason for that is the concepts controllling the read-only mode of textboxes, i.e.: you can change their values on the client if your custom logic requires that, however specifying them as read-only determines that their value will remain unchanged on the server since the end user cannot type into them. Hence when you decide to change the textbox value on the client, you should be aware of that fact and prevent postbacks or notify the users about that detail if necessary.

    Still you can persist the new text in the textboxes (set on the client) by explicitly setting it inside the postback event handler referencing the Request[Control.UniqueID] value. See the code snippets below for further details:

                <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
     
                <script type="text/javascript">  
                 function SetTestValue()  
                 {  
                   var radTxtBox = $find("<%=RadTextBox1.ClientID %>");  
                   radTxtBox.set_value("Test");  
                     
                   var txtBox = $get("<%=txtBox.ClientID %>");  
                   txtBox.value = "Test";  
                 }  
                </script> 
                   
                <input type="button" value="Set 'Test' value in textboxes" onclick="SetTestValue();" /> 
                <asp:Button ID="btnPostBack" runat="server" Text="Postback" OnClick="btnPostBack_Click" /> 
                <br /> 
                RadTextBox  
                <telerik:RadTextBox ID="RadTextBox1" runat="server" ReadOnly="true" /> 
                <br /> 
                MS TextBox  
                <asp:TextBox ID="txtBox" runat="server" ReadOnly="true" /> 

        protected void btnPostBack_Click(object sender, EventArgs e)  
        {  
            RadTextBox1.Text = Request[RadTextBox1.UniqueID];  
            txtBox.Text = Request[txtBox.UniqueID];  
        } 

    Best regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top