Hi Folks !
how to get a reference to module in LocalizedUserControl ? the base class does not expose the module.
You can inherit from BaseModuleControl instead. It has the Module property.
Or is there a reason why you don't want to do this?
for some reason i want to use LocalizedUserControl instead , hopefully there is a way to do so..
Could you explain the scenario where you need this functionality? BaseModuleControl does inherit from LocalizedUserControl, so with using BaseModuleControl, you'll also have the functionality of LocalizedUserControl.
One thing that is possible tough, is to get a reference to the active section, but that one is only set when requesting the page with an explicit url like
http://myhost/34/section.aspx.
PageEngine thePage = this.Page as PageEngine;
if (thePage != null && thePage.ActiveSection != null)
{
Module myModule = thePage.ActiveSection.Module;
}
for some reason
BaseModuleControl generates error when i sent it parameters in a repeater
and nothing special about the base class for this web control :
public partial class ItemView : Cuyahoga.Web.UI.LocalizedUserControl
{
public int ItemID;
public string ItemImage;
public string ItemName;
..................
it generates error when i inherit from
BaseModuleControl
And the repeater is inside another module user control?
What is the error you're getting?
the error :
Server Error in '/Cuyahoga' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Cuyahoga.Web.UI.BaseModuleControl.OnInit(EventArgs e) +13
Cuyahoga.Modules.Auction.Web.ItemView.OnInit(EventArgs e) +47
System.Web.UI.Control.InitRecursive(Control namingContainer) +333
System.Web.UI.Control.InitRecursive(Control namingContainer) +210
System.Web.UI.Control.AddedControl(Control control, Int32 index) +198
System.Web.UI.ControlCollection.Add(Control child) +80
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +107
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +459
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +54
System.Web.UI.WebControls.BaseDataList.DataBind() +55
Cuyahoga.Modules.Auction.Web.Auctions.BindItems() +78
Cuyahoga.Modules.Auction.Web.Auctions.Page_Load(Object sender, EventArgs e) +55
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
the codes excluding the arrows for validation :
views:ItemView ID="ItemView1" runat="server" ItemID='%#Eval("Id")%' ItemImage='%#Eval("ImageUrl")%' ItemName='%#Eval("Name")%'
and the forum module need some modifications ! :) <-- smile
Hi,
If ItemView is a control that you've written, can you not add the following to your code behind for that...
private Cuyahoga.Core.Domain.ModuleBase _module;
public Cuyahoga.Core.Domain.ModuleBase Module {
get { return _module; }
set { _module = value; }
}
Then you can pass a reference to the module from the control the repeater is in (that inherits BaseModuleControl?)...
{views:ItemView ID="ItemView1" runat="server" ItemID='{%# Eval("Id")%}' ItemImage='{%# Eval("ImageUrl")%}' ItemName='{%# Eval("Name")%}' Module='{%# Module %}' /}
Ian
Hi eeun,
Thanks for your reply
i bind Items List to the repeater which holds the view, the question is how i will inject the module reference to the binding ?
Hey,
Does the control that houses the repeater inherit from BaseModuleControl? If so, in the repeater context you will be able to access your current module with the following tag (if you change to the right brackets)...
{%# Module %}
Inside the repeater you have access to all the properties, functions and variables from the control (ascx) that the repeater is in. So if you can access the Module property in the ascx, you can access it from inside the repeater.
Hope this answers your question,
Ian
Hey,
the class the the repeater inherit from LocalizedUserControl , and injecting the module reference via data binding generating null reference exception !
back to using BaseModuleControl , it generates errors as well ! , don't know why actually ...