1

I have a page, which has a public property of type myCustomWebProfile.

In code behind I have a textbox, and I am trying to bind the text box, to a property of my web profile described above.

No matter which variations of the binding syntax I use - the textbox is never populated when it's rendered.

Any help will be greatly appreciated.

Here is the C# code-behind class:

public partial class Profile : selfSvcPage
    {
        public WebProfile pgProfile { get; set; }

        protected void Page_Init(object sender, EventArgs e)
        {
            pgProfile = WebProfile.Current;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            object o = WebProfile.Current.FirstName;
            //Successfully populates with a string

            object b = DataBinder.Eval(pgProfile, "FirstName");
            //Successfully populates with a string
        }
    }

Here is the code markup:

<telerik:RadTextBox ID="FirstName" Text='<%# Eval("pgProfile.FirstName")     %>' SkinID="formText" CssClass="formField" runat="server"/>
Arief
  • 6,055
  • 7
  • 37
  • 41
RobD
  • 1,695
  • 2
  • 24
  • 49

3 Answers3

2

Try this:

<telerik:RadTextBox ID="FirstName" Text='<%# pgProfile.FirstName %>' SkinID="formText" CssClass="formField" runat="server"/>

And this:

protected void Page_PreRenderComplete(object sender, EventArgs e)
{
    DataBind();
}

In your situation you might want to bind at an earlier stage. Refer to this for details:

Why will <%= %> expressions as property values on a server-controls lead to a compile errors?

The important part: 'As the last thing i noticed... When i try with <%# %> + Control.DataBind(), then i get what i would expect. '

Community
  • 1
  • 1
rciq
  • 1,309
  • 10
  • 10
1

Can you just do this in your Page_Load:

FirstName.Text = pgProfile.Current.FirstName;

Make sure the initialization of your pgProfile happens before the code above.

Arief
  • 6,055
  • 7
  • 37
  • 41
  • Thanks for idea Arief, I had considered this, but I'm wanting to keep the databinding on the codebehind for tidiness and to improve maintainability. Additionally, I'd be intrigued to get to the root of this problem, rather than work around it - It just looks to me as though it 'should' work, I wish I knew why its not working. – RobD May 24 '11 at 09:43
  • hi RobD, my answer shows you databinding on codebehind. and also if i'm not mistaken, textbox does not support databinding, that's why your code won't work, I don't know about telerik textbox though. – Arief May 24 '11 at 09:52
0

What i got from your code is you have a

class Profile

in that class you have made a property of a class webProfile.

Now by using this property you are trying to assign value i think you can try some thing like this

Text='<%#(DataBinder.Eval(Container.DataItem, "pgProfile.Current.FirstName")).ToString()%>'
ankur
  • 4,565
  • 14
  • 64
  • 100