[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

Bind a TextBox to an object of my page


In an ASP.NET Web application I have an ASPX page that contains TextBox.
This page contains an attribute that is an object "Eleve".

At the beginning of my file ASPX.CS I wrote:
public static Eleve objEleveCourant;

In my ASPX page can I bind my TextBox controls directly to a property of my object "objEleveCourant" ?

For example like this:
<asp: TextBox id = "TxtNom" runat = "server" Text ='<%# Bind ("objEleveCourant.nom") %>'></ asp: TextBox>

thank you in advance for your help.
1 Solution
If you have declared your Eleve object on your ASP.NET page (the HTML page), you shouldn't have to add a separate declaration for it here. ASP.NET should automatically wire up a reference to it for your codebehind (although you DID have to do this in very early versions of ASP.NET).

Bind is normally associated with a databound control, one that is hooked to some type of datasource.

If you just want the text box to have the value of the "nom" property of your Eleve object, just try this:

protected void Page_Load(object sender, args e)
    TxtNom.Text = objEleveCourant.nom;

Open in new window

I hope I am  understanding your problem properly, and also hope this provides you with some help.

agxinfoAuthor Commented:

ok, Thank you very much !

that's I thought, but I was wondering if there was a solution more automatic.
Maybe in a future version of ASP.NET...

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now