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

RadTextbox binding does not update the underlying object

1 Answer 232 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
dotnetshar net
Top achievements
Rank 1
dotnetshar net asked on 26 Jan 2011, 03:15 AM
Hoping
I have an object (skuform),whose property(SKUCode) is bound to a textbox.
If I run this form , change the value in the textbox (say "test123"), and hit the button, I notice that the object's (skuForm) property does not reflect the new value ("test123"), could you please suggest what could be wrong.

  <td><telerik:RadTextBox runat="server" ID="txtSKUCode"  
                   text='<%# skuForm.SKUCode %>' EnableViewState="true"      Wrap="false" 
                   ontextchanged="txtSKUCode_TextChanged"></telerik:RadTextBox></td></tr> 
<telerik:RadButton ID="RadButton1" 
                    runat="server" onclick="RadButton1_Click">
                </telerik:RadButton>

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 31 Jan 2011, 12:38 PM
Hello,

When you bind the Text property with inline <%# %> tags, the value from datasource is copied for Text. But this is one way binding and when you change the Text property the object use as a datasource is not changed. You can change the datasource object in TextChanged event of the RadTextBox like in the code-bellow:

Aspx:
<telerik:RadTextBox runat="server" ID="radTextBox1" Text='<%# obj1.Code %>' EnableViewState="true"
  OnTextChanged="radTextBox1_TextChanged">
</telerik:RadTextBox>
<asp:TextBox ID="TextBox1" runat="server" D="radTextBox1" Text='<%# obj1.Code2 %>'></asp:TextBox>
<telerik:RadButton ID="RadButton1" Text="Button" runat="server" OnClick="RadButton1_Click">
</telerik:RadButton>
C#:
public class dataClass
{
    public string Code
    {
        get;
        set;
    }
    public string Code2
    {
        get;
        set;
    }
}
 
public dataClass obj1 = new dataClass();
 
protected void Page_Load(object sender, EventArgs e)
{
    obj1.Code = "Default code";
    obj1.Code2 = "Default code";
}
 
protected void RadButton1_Click(object sender, EventArgs e)
{
    string code = obj1.Code; //will return the new entered text
    string code2 = obj1.Code2; // will return default text
}
protected void radTextBox1_TextChanged(object sender, EventArgs e)
{
    obj1.Code = (sender as RadTextBox).Text;
}

You will find more information about binding here.

Greetings,
Vasil
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
General Discussions
Asked by
dotnetshar net
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or