DotNetNuke MVP Module Development: Tip #1 The AutoDataBind Property

The DotNetNuke.Web.Mvp.ModuleViewBase sets a property called ‘AutoDataBind = true’.  As a result the DataBind() method for the page is always called in the Page_PreRenderComplete event. 

If you use the following familiar snippet of code you find that your controls will be data bound twice.  Once when your code calls DataBind() and a second time when it is called during the Page_PreRenderComplete event.

ddlStatus.DataSource = Model.StatusList;
ddlStatus.DataBind();

Here is an example of how to properly bind a DropDownList for an MVP based module.

<asp:DropDownList ID="ddlStatus" runat="server"
    DataSource='<%#Model.StatusList%>'
    DataTextField="Description"
    DataValueField="Id"    SelectedValue='<%#Model.Post.PostStatus %>'>
</asp:DropDownList>

It is important to point out again that you should not call ddlStatus.DataBind() from the code behind.  Calling this is a waste because the AutoDataBind property is going to force everything to rebind again during Page_PreRenderComplete.

2 thoughts on “DotNetNuke MVP Module Development: Tip #1 The AutoDataBind Property

  1. Pingback: Tweets that mention aaronkjackson.com » DotNetNuke MVP Module Development: Tip #1 The AutoDataBind Property -- Topsy.com

  2. Pingback: aaronkjackson.com » DotNetNuke MVP Module Development: Tip #2 Disable AutoDataBind

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>