5

I have seen that BindableAttribute is used to decorate public properties in custom controls.

MSDN briefly mentions that it provides the ability to control the binding direction and whether binding is supported at design time.

public class MyControl : Panel
{
    [Bindable(BindableSupport.No, BindingDirection.OneWay)]
    public string MyString { get; set; }
}

var myControl = new MyControl();
var myString = myControl.MyString;

Questions:

1) I set BindableSupport to No, however I could still do this in markup (.aspx). What does BindableSupport affect then? Does it hide the property in the toolbox?

<cc:MyControl runat="server" MyString="something" />

2) How does one-way binding and two-way binding work in the context of custom controls and ASP.NET?

Would appreciate any inputs.

Channs
  • 2,091
  • 1
  • 15
  • 20

2 Answers2

1

I believe MSDN is clear enough about this. It may be brief in your eyes, but it's sufficient. This attribute is used for BINDING. Assigning a string to your variable isn't considered a binding.

This is for instance binding:

myGridView.DataSource = myList;
myGridView.DataBind();

This isn't:

myGridView.ID = "blablabla";

Please, see this link for more info, don't see a reason to duplicate an existing learning source here...

http://msdn.microsoft.com/en-us/library/ms752347.aspx

UPDATE:

For asp.net this link may be more illustrative:

http://www.asp.net/ajaxlibrary/HOW%20TO%20Create%20an%20Editable%20View%20with%20Two-Way%20Data%20Binding.ashx

walther
  • 13,466
  • 5
  • 41
  • 67
  • Thanks for answering my first question, I now understand the real meaning of 'binding'. About my second question, the MSDN resource you mentioned talks about WPF, I know how two-way binding is relevant to thick client apps in WPF. But how does two-way binding work in a web environment like ASP.NET? E.g. Suppose I change my property on the server, it wouldn't affect the control rendered on the browser automatically. I don't think this is obvious, if it is, I will delete my question. Thanks. – Channs Jun 27 '12 at 16:04
  • @channs,please, see the update. Hopefully it will help you to understand how to do that :) – walther Jun 27 '12 at 16:16
1

My findings so far:

1) BindableSupport is related to data-binding functionality provided by ASP.NET. E.g. Page.DataBind(), <%# Bind("MyProperty") %>, <%# Eval ("MyProperty") %> and so on. +1 for @walther's answer.

2) Two-way binding in ASP.NET is the ability to retain modifications to data-bound values on postback. This SO thread provides more details. Bind is two-way, while Eval is one-way.

Community
  • 1
  • 1
Channs
  • 2,091
  • 1
  • 15
  • 20