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

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

4 Answers 221 Views
Input
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 31 Jul 2009, 12:30 AM
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!

4 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 05 Aug 2009, 07:42 AM
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.
0
Miao Weibin
Top achievements
Rank 1
answered on 26 Aug 2009, 06:41 AM
if ReadOnly is set, the value cannot be persisted when postback.
0
Shinu
Top achievements
Rank 2
answered on 26 Aug 2009, 10:04 AM
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.
0
Sebastian
Telerik team
answered on 26 Aug 2009, 10:24 AM
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.
Tags
Input
Asked by
John
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Miao Weibin
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or