1

Task – develop user control, which has <%#Bind(“expression”)%>`

How send parametrs into user control and how to use Bind and Eval ?

3
  • 2
    Sounds like you're asking us to do your homework for you... tisk tisk. Commented Jan 26, 2012 at 19:47
  • I try learn Asp, maybe this task is very easy for you, but I dont know how do it, better you will recomend some tutorial, sample etc. Commented Jan 26, 2012 at 19:58
  • Do a web search for "ASP.NET data binding" you will find TONS of tutorials. Commented Jan 26, 2012 at 20:00

1 Answer 1

2

There is a good tutorial about creating user controls and setting their properties in this MSDN Article.

Basically, you create an ascx page and its code-behind. In the code-behind, you create the properties that you want exposed and store their values using ViewState. It is important for your property backing store to be viewstate for reasons discussed in this article:

public partial class MyControl : System.Web.UI.UserControl { public DateTime BeginDate { get { return (DateTime)(ViewState["BeginDate"] ?? new DateTime()); } set { ViewState["BeginDate"] = value; } } ...... 

The after you register this new user control in your web.config file, you can declarative place an instance of the control in your hosting page and set its property:

<Custom:MyControl Id="Mycontrol" runat="server" BeginDate ="2012-01-26" /> 

If you want to use databinding to set the value of the control, simply assign the value of the property to a databinding expression:

<Custom:MyControl Id="Mycontrol" runat="server" BeginDate ='<%# GetBeginDate() %>' /> 

Where GetBeginDate() is a public or protected method in your code behind page that returns a date.

You can see this article for a good description of the basics of databinding.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.