3

I have an Address User control.

    <fieldset>
    <legend><%#Title%></legend>
<div>
<div>Country</div>
    <div><uc:TextBox ID="txtCountry" runat="server" /></div>
</div>


<div>
<div>City</div>    
    <div><uc:TextBox ID="txtCity" runat="server" /></div>
</div>


<div>
<div>Street</div>     
    <div><uc:TextBox ID="txtStreet" runat="server"/></div>
</div>
</fieldset>

And CodeBehind

private BEAddress _address;
    public BEAddress Address
    {

        get
        {
            if (CoordinatesVisible)
            {
                _address = new BEAddress()
                {
                    Country = txtCountry.Text,
                    City = txtCity.Text,
                    Street = txtStreet.Text,
                    Block = txtBlock.Text,
                    Building = txtBuilding.Text,

                    Latitude = txtLatitude.Text,
                    Longitude = txtLongitude.Text
                };
            }
            else
            {
                _address = new BEAddress()
                {
                    Country = txtCountry.Text,
                    City = txtCity.Text,
                    Street = txtStreet.Text,
                    Block = txtBlock.Text,
                    Building = txtBuilding.Text

                };
            }
            return _address;
        }


        set
        {
            if (CoordinatesVisible)
            {
                _address = new BEAddress()
                {
                    Country = value.Country,
                    City = value.City,
                    Street = value.Street,
                    Block = value.Block,
                    Building = value.Building,

                    Latitude = value.Latitude,
                    Longitude = value.Longitude
                };
            }
            else
            {
                _address = new BEAddress()
                {
                    Country = value.Country,
                    City = value.City,
                    Street = value.Street,
                    Block = value.Block,
                    Building = value.Building,

                    Latitude = value.Latitude,
                    Longitude = value.Longitude
                };
            }
        }

    }

How do I do simple data binding? I want to something like this

<uc:Address runat="server" ID="uc1" Address=<%#GetAddress %> />

1 Answer 1

2

There is nothing out of the box in ASP.NET unless you want to use the DetailsView which I don't like at all.

For my programs I wrote a own class that manages the binding for me in a generic way. The idea behind was to bind a control property to a object property.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.