Bind a TextBox to an object of my page

Posted on 2011-04-29
Last Modified: 2012-05-11

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.
Question by:agxinfo
    LVL 7

    Accepted 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.


    Author Comment


    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...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now