So far, I have tried below code to add a module through code on my page in DNN.
protected void Page_Load(object sender, EventArgs e)
{
ModuleController MC = new ModuleController();
ModuleInfo MInfo = new ModuleInfo();
MInfo = MC.GetModule(507, 116,false);//Just Hard coded for testing
MInfo.TabID = PortalSettings.ActiveTab.TabID;
MInfo.PaneName = "ContentPane";
MInfo.Alignment = "left";
MC.AddModule(MInfo);//Line throwing error :-
}
I am trying to add a module which is present on tabid=116
and having moduleId=507
on my current tab or page in pageLoad
Event.But the last line throwing a error saying
"Violation of UNIQUE KEY constraint 'IX_TabModules_UniqueId'. Cannot insert duplicate key in object 'dbo.TabModules'. The duplicate key value is (555ba77a-be19-40a0-bb72-559672230345)."
Please tell me where i am doing wrong ? and is this the correct way to add a module ?