.net - How to create ASP.NET user/server control that uses a list of asp:ListItem as child controls? -


I am looking to create a user / server control that will be created with something similar to the following:

  & lt; My: MyListControl runat = "server" & gt; & Lt; Asp: ListItem text = "Test1" value = "test1" /> & Lt; Asp: ListItem text = "Test2" value = "Test 2" /> & Lt; / My: MyListControl & gt;  

I'm looking for a start here: articles or code samples.

Which base class should I be stabbed? To override what

is the sub-item about customizing your control, perhaps? (Mary: ListItem: ListItem instead of ASP).

What am I doing to make a very simple piece of bread control for a small portion of my site? I am working with all these stock ASP.NET controls, but the item has been added to the code, which means fixing the spelling mistake or formatting bug includes a recompile, which is not ideal.

Edit:

Here is your code with the addition of Josh's suggestion below:

Nameshot MySite.Controls inherited partial class breadcrumbs UserControl

  Private m_BreadCrumbs new list (as BreadCrumbItem) & LT; PersistenceMode (PersistenceMode.InnerProperty) & gt; _Public property items (return) list (BreadCrumbItem) return m_BreadCrumbs termination set (byVal Price List (as BreadCrumbItem)) Go as m_BreadCrumbs = Price end set property property Sub-Page_Load (ByVal As in this object, EventArgs Handle EventArgs as ByVal) End Sub Personal Sub-Band () lvCrumbs.DataSource = Item Me.DataBind () End Sub End Class Orbit BreadCrumbItem Private m_Text string as public property text () Return of the string as m_Text Retrieval Set Setting (ByVal Value String) m_Text = Value End Set Property As Private m_Url String Public Property URL () String Return as m_Url End Set (ByVal Value as String) m_Url = Get Go Price End Set End Property End Class  

And Namespace

Then my page code looks like this:

  <% @ Page language = "VB" inherited in AutoEventWireup = "false" = "MySite.MyPage" Title = "my page" codebehind = "MyPage.aspx.vb"%> & Lt;% @ Register TagPrefix = "my" namespace = "MySite.Control" assembly = "MySwit"% & gt; & Lt; My: breadcrumb id = "breadcrumbs" run = "server" & gt; & Lt; Items & gt; & Lt; My: breadcrumbItem text = "another page" url = "other page. Espacks" /> & Lt; / Item & gt; & Lt; / Mary: breadcrumbs & gt;  

You can add the back asset like code of a user control:

  [DurabilityMode (Persistensum.Inproperty)] Public listing & lt; ListItem & gt; Item {get; Set; }  

Your markup will be:

  & lt; My: MyListControl runat = "server" & gt; & Lt; Items & gt; & Lt; ASP: ListItem / & gt; & Lt; / Item & gt; & Lt; / My: myListControl & gt;  

To do this, the list may be your own list item (which I am advocating to use asp.net). You create your own class Want to

I use a server control here (I remove a lot of noise as if it is just a skeleton):

  [ToolboxData ("& lt; { 0}: Menu Runat = Server & gt; & lt; / {0}: Menu & gt; ")] [System.ComponentModel.DesignTimeVisible (false)] Public Square Menubush: WebControl, IPhonebackAventHandler {Private listing  

Now I can use this way:

   & Lt; My: MenuItem title = "for PDF" Href = "javascript:" /> & Lt; / MenuItems & gt; & Lt; / My: MenuItem & gt; & Lt; / MenuItems & gt; & Lt; / Mary: Menu Bar & gt;  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -