BlogEngine.Net Control Parameters

May 18, 2008
by:   Tim Stanley

How does one add or pass parameter to a user control in BlogEngine.Net?  This may be obvious to others already, but I thought I'd share a quick note on what I found. 

Create The Parameter

First, define the parameter value in the user control.


private String _Name = null;
public String Name
{
    get { return _Name; }
    set { _Name = value; }
}

The parameter now can be set either by embedding the control on another page or user control, or by passing a parameter in the [ usercontrol:~\Control.apx Name=xxx;] format.

Passing Parameters In Pages Or Controls


Register src="../../UserCustom/PageInclude.ascx" mce_src="../../UserCustom/PageInclude.ascx" tagname="PageInclude" tagprefix="uc6"
 
<uc6:PageInclude ID="PageInclude1" runat="server" runat="server" Name="P Test" />

By adding a reference to the user control to a page or other user control, then the values for the parameters can be set. Without the runat="server" value, values will not be passed to the control.

In this particular example, the Name="Some Page" sets the earlier defined _Name value to "Some Page".

Passing Parameters In BlogEngine.Net

BlogEngine.Net behaves very similarly.  All parameters must be separated by a ";" semi-colon character.  If parameters are passed that are not supported, BlogEngine.Net 1.3 code will not render the control and an error message will be displayed.  The example below has spaces added after the bracket.  These need to be removed in the actual page or posting that sets these parameters.


[ usercontrol:~\UserCustom\PageInclude.ascx Name=SomeName; ] 

 

Multiple parameter example:


[ usercontrol:~\UserCustom\PageInclude.ascx Name=Some Name; Value=Some Value; ]

Related Items