Error loading customControl (Assembly: Promex.Casius.Common, Type: 'Promex.Casius.Common.Controls.Installation.InstallationProjectForm' Exception has been thrown by the target of an invocation. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at umbraco.macro.loadControl(String fileName, String controlName, Hashtable attributes, Hashtable pageElements) at umbraco.macro.renderMacro(Hashtable attributes, Hashtable pageElements, Int32 pageId)
When I hit the refresh button, the control is loaded normally and everything works fine untill I close down the page and revisit it, ... than the fun starts all over again. I tried forums, checked wether my namings are correct, checked that there is indeed a value supplied to the macro.
umbraco v
4.0.2.1 (Assembly version: 1.0.3441.17657) Windows vista business (workplace) Windows server web 2008 (place of umbracoinstallation) IIS7
using System; using System.Collections; using System.Collections.Generic; using System.Text; using BL = Promex.Casius.BusinessLogic; using WC = System.Web.UI.WebControls; using System.Web.UI; using System.Web; using Promex.Casius.BusinessLogic.Installation; using Promex.Casius.BusinessLogic.ProjectMap;
namespace Promex.Casius.Common.Controls.Installation { /// <summary> /// This form gives clients of affiliates the opportunity to order products of their stock. /// </summary> public class InstallationProjectForm : System.Web.UI.WebControls.Panel {
/// <summary> /// When a projectID exists in the session, the user allready filled in the form and is redirected to login or summary. Otherwise the form is rendered /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (HttpContext.Current.Session[SessionProperty.InstallationIntakeProjectID.ToString()] != null) { if (User.GetCurrent() == null) { Logging.WriteToLog("Redirect", "redirecting to :" + umbraco.library.NiceUrl(redirectForLogin)); HttpContext.Current.Response.Redirect(umbraco.library.NiceUrl(redirectForLogin)); } else { Logging.WriteToLog("Redirect", "redirecting to :" + umbraco.library.NiceUrl(redirectToSummary)); HttpContext.Current.Response.Redirect(umbraco.library.NiceUrl(redirectToSummary) + "?umbDebugShowTrace=true"); } } else RenderInstallationIntakeForm(); }
/// <summary> /// Renders the installation intake form. /// </summary> private void RenderInstallationIntakeForm() { //add categories for the network addCategories(); this.Controls.Add(new LiteralControl("<div clear=\"both\"> </div>")); this.Controls.Add(new System.Web.UI.LiteralControl("<br/><br/>"));
//add pricing information addPricing(); this.Controls.Add(new LiteralControl("<div clear=\"both\"> </div>")); this.Controls.Add(new System.Web.UI.LiteralControl("<br/><br/>"));
//retrieve network to get VAT information Network n = Network.FetchById((int)NetworkID); //add hidden textbox to retrieve vat1 info for javascript this.Controls.Add(new LiteralControl("<input type=\"hidden\" name=\"" + n.VAT1 + "\" rel=\"vat\" id=\"vat" + n.VAT1 + "\" />"));
WC.Label lblTotalInclVAT1 = new WC.Label(); lblTotalInclVAT1.Text = String.Format(Translation.getTranslation("InstallationIntake_TotalInclBTW"), n.VAT1);
//when coming from affiliate try to get the total price out of the session if (HttpContext.Current.Session[SessionProperty.AffiliateInfo.ToString()] != null) { String totalText; if (affInfo.TryGetValue("O", out totalText)) txtTotalInclVAT1.Text = totalText; }
//check if VAT2 is supplied and show it if (n.VAT2 != null) { //add hidden textbox to retrieve vat1 info for javascript this.Controls.Add(new LiteralControl("<input type=\"hidden\" name=\"" + n.VAT2 + "\" rel=\"vat\" id=\"vat" + n.VAT2 + "\" />"));
WC.Label lblTotalInclVAT2 = new WC.Label(); lblTotalInclVAT2.Text = String.Format(Translation.getTranslation("InstallationIntake_TotalInclBTW"), n.VAT2);
WC.TextBox txtTotalInclVAT2 = new WC.TextBox(); txtTotalInclVAT2.ID = "TotalInclVAT2"; txtTotalInclVAT2.Attributes.Add("rel", "TotalInclVAT2"); int totalInclVAT1 = Convert.ToInt32(txtTotalInclVAT1.Text); int totalExclVAT = totalInclVAT1 - (totalInclVAT1 * ((int)n.VAT1 / 100)); int totalInclVAT2 = totalExclVAT + (totalExclVAT * ((int)n.VAT2 / 100)); txtTotalInclVAT2.Text = totalInclVAT2.ToString();
//add the brands to the cat list foreach (InstallationBrand brand in brands) { CheckTextBox ctb = new CheckTextBox(brand, "Eur"); pnlDetail.Controls.Add(ctb); }
Macro needs a page refresh before it will load.
Hi,
The first time the page is called the macro cannot be loaded.
This is the macro
<umbraco:Macro redirectToSummary="[#summaryRedirect]" redirectForLogin="[#loginRedirect]" Alias="IntakeInstallation" />
here is the umbracoDebug
Error loading customControl (Assembly: Promex.Casius.Common, Type: 'Promex.Casius.Common.Controls.Installation.InstallationProjectForm'
Exception has been thrown by the target of an invocation.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at umbraco.macro.loadControl(String fileName, String controlName, Hashtable attributes, Hashtable pageElements)
at umbraco.macro.renderMacro(Hashtable attributes, Hashtable pageElements, Int32 pageId)
When I hit the refresh button, the control is loaded normally and everything works fine untill I close down the page and revisit it, ... than the fun starts all over again. I tried forums, checked wether my namings are correct, checked that there is indeed a value supplied to the macro.
umbraco v 4.0.2.1 (Assembly version: 1.0.3441.17657)
Windows vista business (workplace)
Windows server web 2008 (place of umbracoinstallation)
IIS7
Please, be able to help me.
Hi,
This seems more like a problem with the 'IntakeInstallation' module rather than Umbraco.
What does this module do? Can you post the code for this control?
Chris
It's alot, but here goes nothing.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using BL = Promex.Casius.BusinessLogic;
using WC = System.Web.UI.WebControls;
using System.Web.UI;
using System.Web;
using Promex.Casius.BusinessLogic.Installation;
using Promex.Casius.BusinessLogic.ProjectMap;
namespace Promex.Casius.Common.Controls.Installation
{
/// <summary>
/// This form gives clients of affiliates the opportunity to order products of their stock.
/// </summary>
public class InstallationProjectForm : System.Web.UI.WebControls.Panel
{
private decimal NetworkID = (decimal)HttpContext.Current.Session[SessionProperty.AffNetworkID.ToString()];
private Dictionary<string, string> affInfo = (Dictionary<string, string>)HttpContext.Current.Session[SessionProperty.AffiliateInfo.ToString()];
protected override void OnInit(EventArgs e) {
base.OnInit(e);
}
/// <summary>
/// When a projectID exists in the session, the user allready filled in the form and is redirected to login or summary. Otherwise the form is rendered
/// </summary>
/// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
if (HttpContext.Current.Session[SessionProperty.InstallationIntakeProjectID.ToString()] != null) {
if (User.GetCurrent() == null) {
Logging.WriteToLog("Redirect", "redirecting to :" + umbraco.library.NiceUrl(redirectForLogin));
HttpContext.Current.Response.Redirect(umbraco.library.NiceUrl(redirectForLogin));
} else {
Logging.WriteToLog("Redirect", "redirecting to :" + umbraco.library.NiceUrl(redirectToSummary));
HttpContext.Current.Response.Redirect(umbraco.library.NiceUrl(redirectToSummary) + "?umbDebugShowTrace=true");
}
} else
RenderInstallationIntakeForm();
}
/// <summary>
/// Renders the installation intake form.
/// </summary>
private void RenderInstallationIntakeForm() {
//add categories for the network
addCategories();
this.Controls.Add(new LiteralControl("<div clear=\"both\"> </div>"));
this.Controls.Add(new System.Web.UI.LiteralControl("<br/><br/>"));
//add pricing information
addPricing();
this.Controls.Add(new LiteralControl("<div clear=\"both\"> </div>"));
this.Controls.Add(new System.Web.UI.LiteralControl("<br/><br/>"));
//question answers
addQuestionAnswers();
this.Controls.Add(new LiteralControl("<div clear=\"both\"> </div>"));
this.Controls.Add(new System.Web.UI.LiteralControl("<br/><br/>"));
//add comment box
WC.Label lblComment = new System.Web.UI.WebControls.Label();
lblComment.Text = Translation.getTranslation("InstallationIntake_InstallComment");
WC.TextBox txtComment = new WC.TextBox();
txtComment.ID = "comment";
txtComment.TextMode = WC.TextBoxMode.MultiLine;
txtComment.Columns = 60;
txtComment.Rows = 7;
txtComment.Wrap = true;
this.Controls.Add(txtComment);
this.Controls.Add(new System.Web.UI.LiteralControl("<br/>"));
TextBoxCounter count = new TextBoxCounter();
count.ControlToCount = txtComment.ID;
count.MaxCharacters = 512;
this.Controls.Add(count);
this.Controls.Add(new System.Web.UI.LiteralControl("<br/><br/>"));
//add button submit
System.Web.UI.WebControls.Button submitbutton = new System.Web.UI.WebControls.Button();
submitbutton.Text = Translation.getTranslation("Common_Submit");
submitbutton.ID = "btnsubmit";
submitbutton.ValidationGroup = "submit";
submitbutton.Click += new EventHandler(submitbutton_Click);
this.Controls.Add(submitbutton);
this.Controls.Add(new System.Web.UI.LiteralControl("<br/><br/>"));
//add cancelation Condition
WC.Label lblCancelConditions = new System.Web.UI.WebControls.Label();
lblCancelConditions.Text = Translation.getTranslation("InstallationIntake_CancelConditions");
this.Controls.Add(lblCancelConditions);
}
private void addPricing() {
//get pricing info for network and add to table
float prevPrice = 0;
float VariableCost = 0;
float InstallationPrice = 0;
Table tblVariableCost = new Table();
TableHeaderRow hr = new TableHeaderRow();
TableHeaderCell hc1 = new TableHeaderCell();
TableHeaderCell hc2 = new TableHeaderCell();
hc1.Text = Translation.getTranslation("InstallationIntake_THInstallationPriceInEuro");
hc2.Text = Translation.getTranslation("InstallationIntake_THOnceOnlyVariableCost");
hr.Cells.Add(hc1);
hr.Cells.Add(hc2);
tblVariableCost.Rows.Add(hr);
List<NetworkPrice> networkPrices = NetworkPrice.FetchByParametersAsList(new PropertyParameter("NetworkID", NetworkID));
foreach (NetworkPrice networkPrice in networkPrices) {
String price; String cost;
//add hidden textboxes to retrieve pricing data in javascript
this.Controls.Add(new LiteralControl("<input type=\"hidden\" name=\""+networkPrice.InstallationMaximumPrice + "," + networkPrice.VariablePrice +"\" rel=\"networkPrice\" id=\"networkPrice"+ networkPrice.InstallationMaximumPrice + "\" />"));
// calculate price info
if (networkPrices.IndexOf(networkPrice) == 0) {
//add till ( tot € )
price = String.Format("{0} €{1}\r\n", Translation.getTranslation("InstallationIntake_Till"), networkPrice.InstallationMaximumPrice);
if (InstallationPrice < networkPrice.InstallationMaximumPrice) {
VariableCost = networkPrice.VariablePrice;
}
} else if (networkPrices.IndexOf(networkPrice) < (networkPrices.Count - 1)) {
// add to (€ tot €)
price = String.Format("€{0} {1} €{2}\r\n", prevPrice, Translation.getTranslation("InstallationIntake_Till").ToLower(), networkPrice.InstallationMaximumPrice);
if (InstallationPrice >= prevPrice && InstallationPrice < networkPrice.InstallationMaximumPrice) {
VariableCost = networkPrice.VariablePrice;
}
} else {
//add more then (meer dan €)
price = String.Format("{0} €{1}\r\n", Translation.getTranslation("InstallationIntake_MoreThan"), prevPrice);
if (InstallationPrice >= prevPrice) {
VariableCost = networkPrice.VariablePrice;
}
}
cost = String.Format("€{0}", networkPrice.VariablePrice);
prevPrice = networkPrice.InstallationMaximumPrice;
//add priceInfo as table for easy readout
TableRow tr = new TableRow();
TableCell c1 = new TableCell();
TableCell c2 = new TableCell();
c1.Text = price;
c2.Text = cost;
tr.Cells.Add(c1);
tr.Cells.Add(c2);
tblVariableCost.Rows.Add(tr);
}
WC.Label lblSingleCostInfo = new WC.Label();
lblSingleCostInfo.Text = Translation.getTranslation("InstallationIntake_SingleCostInfo");
this.Controls.Add(lblSingleCostInfo);
this.Controls.Add(new System.Web.UI.LiteralControl("<br/>"));
this.Controls.Add(tblVariableCost);
this.Controls.Add(new System.Web.UI.LiteralControl("<br/>"));
// add all prices
WC.Label lblInstallationPrice = new WC.Label();
lblInstallationPrice.Text = Translation.getTranslation("InstallationIntake_InstallationPrice");
WC.TextBox txtInstallationPrice = new WC.TextBox();
txtInstallationPrice.ID = "InstallationPrice";
txtInstallationPrice.Attributes.Add("rel", "InstallationPrice");
txtInstallationPrice.Text = "€0";
WC.Label lblSingleCost = new WC.Label();
lblSingleCost.Text = Translation.getTranslation("InstallationIntake_SingleCost");
WC.TextBox txtSingleCost = new WC.TextBox();
txtSingleCost.ID = "SingleCost";
txtSingleCost.Attributes.Add("rel", "SingleCost");
txtSingleCost.Text = "€0";
//retrieve network to get VAT information
Network n = Network.FetchById((int)NetworkID);
//add hidden textbox to retrieve vat1 info for javascript
this.Controls.Add(new LiteralControl("<input type=\"hidden\" name=\"" + n.VAT1 + "\" rel=\"vat\" id=\"vat" + n.VAT1 + "\" />"));
WC.Label lblTotalInclVAT1 = new WC.Label();
lblTotalInclVAT1.Text = String.Format(Translation.getTranslation("InstallationIntake_TotalInclBTW"), n.VAT1);
WC.TextBox txtTotalInclVAT1 = new WC.TextBox();
txtTotalInclVAT1.ID = "TotalInclVAT1";
txtTotalInclVAT1.Attributes.Add("rel", "TotalInclVAT1");
txtTotalInclVAT1.Text = "0";
//when coming from affiliate try to get the total price out of the session
if (HttpContext.Current.Session[SessionProperty.AffiliateInfo.ToString()] != null) {
String totalText;
if (affInfo.TryGetValue("O", out totalText))
txtTotalInclVAT1.Text = totalText;
}
//prices as table
this.Controls.Add(new LiteralControl("<table id=\"totalpricelist\"><tbody>"));
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(lblInstallationPrice);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(txtInstallationPrice);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(lblSingleCost);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(txtSingleCost);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(lblTotalInclVAT1);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(txtTotalInclVAT1);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));
//check if VAT2 is supplied and show it
if (n.VAT2 != null) {
//add hidden textbox to retrieve vat1 info for javascript
this.Controls.Add(new LiteralControl("<input type=\"hidden\" name=\"" + n.VAT2 + "\" rel=\"vat\" id=\"vat" + n.VAT2 + "\" />"));
WC.Label lblTotalInclVAT2 = new WC.Label();
lblTotalInclVAT2.Text = String.Format(Translation.getTranslation("InstallationIntake_TotalInclBTW"), n.VAT2);
WC.TextBox txtTotalInclVAT2 = new WC.TextBox();
txtTotalInclVAT2.ID = "TotalInclVAT2";
txtTotalInclVAT2.Attributes.Add("rel", "TotalInclVAT2");
int totalInclVAT1 = Convert.ToInt32(txtTotalInclVAT1.Text);
int totalExclVAT = totalInclVAT1 - (totalInclVAT1 * ((int)n.VAT1 / 100));
int totalInclVAT2 = totalExclVAT + (totalExclVAT * ((int)n.VAT2 / 100));
txtTotalInclVAT2.Text = totalInclVAT2.ToString();
this.Controls.Add(new LiteralControl("<tr>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(lblTotalInclVAT2);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("<td>"));
this.Controls.Add(txtTotalInclVAT2);
this.Controls.Add(new LiteralControl("</td>"));
this.Controls.Add(new LiteralControl("</tr>"));
}
this.Controls.Add(new LiteralControl("</tbody></table>"));
this.Controls.Add(new System.Web.UI.LiteralControl("<br/><br/>"));
}
private void addQuestionAnswers() {
List<QuestionAnswer> qas = QuestionAnswer.FetchByParametersAsList(
new BL.PropertyParameter(QuestionAnswer.Properties.NetworkID, NetworkID),
new BL.PropertyParameter(QuestionAnswer.Properties.Active, 1));
foreach (QuestionAnswer qa in qas) {
this.Controls.Add(new System.Web.UI.LiteralControl("<br/><strong>" + qa.QuestionText + "</strong><br/>"));
Logging.WriteToLog("QA", "qa : " + qa.QuestionText);
//Add Answer
switch (qa.AnswerMode.ToLower()) {
case "textbox":
System.Web.UI.WebControls.TextBox textbox = new System.Web.UI.WebControls.TextBox();
textbox.ID = "answer" + qa.UniqueId;
if (qa.Required) {
System.Web.UI.WebControls.RequiredFieldValidator reqfield = new System.Web.UI.WebControls.RequiredFieldValidator();
reqfield.ControlToValidate = textbox.ClientID;
reqfield.ValidationGroup = "submit";
reqfield.ErrorMessage = "*";
this.Controls.Add(reqfield);
}
if (qa.RequestStringKeyMap != null) {
if (HttpContext.Current.Session[SessionProperty.AffiliateInfo.ToString()] != null) {
if (affInfo.ContainsKey(qa.RequestStringKeyMap)) {
textbox.Text = affInfo[qa.RequestStringKeyMap];
}
}
}
this.Controls.Add(textbox);
break;
case "listbox":
DropDownList listbox = new DropDownList();
listbox.CodeType = qa.AnswerCodeType;
listbox.ID = "answer" + qa.UniqueId;
if (qa.Required) {
DropDownListValidator ddreqfield = new DropDownListValidator();
ddreqfield.ControlToValidate = listbox.ClientID;
ddreqfield.ValidationGroup = "submit";
ddreqfield.ErrorMessage = "*";
this.Controls.Add(ddreqfield);
}
if (qa.RequestStringKeyMap != null) {
if (HttpContext.Current.Session[SessionProperty.AffiliateInfo.ToString()] != null) {
if (affInfo.ContainsKey(qa.RequestStringKeyMap)) {
listbox.SelectedIndex = Int32.Parse(affInfo[qa.RequestStringKeyMap]);
}
}
}
this.Controls.Add(listbox);
break;
case "checkbox":
CheckboxList checkbox = new CheckboxList();
checkbox.CodeType = qa.AnswerCodeType;
checkbox.ID = "answer" + qa.UniqueId;
if (qa.Required) {
ListValidator clistreqfield = new ListValidator();
clistreqfield.ControlToValidate = checkbox.ClientID;
clistreqfield.ValidationGroup = "submit";
clistreqfield.ErrorMessage = "*";
this.Controls.Add(clistreqfield);
}
if (qa.RequestStringKeyMap != null) {
if (HttpContext.Current.Session[SessionProperty.AffiliateInfo.ToString()] != null) {
if (affInfo.ContainsKey(qa.RequestStringKeyMap)) {
checkbox.SelectedIndex = Int32.Parse(affInfo[qa.RequestStringKeyMap]);
}
}
}
this.Controls.Add(checkbox);
break;
case "optiongroup":
RadioButtonList optiongroup = new RadioButtonList();
optiongroup.CodeType = qa.AnswerCodeType;
optiongroup.ID = "answer" + qa.UniqueId;
if (qa.Required) {
ListValidator listreqfield = new ListValidator();
listreqfield.ControlToValidate = optiongroup.ClientID;
listreqfield.ValidationGroup = "submit";
listreqfield.ErrorMessage = "*";
this.Controls.Add(listreqfield);
}
this.Controls.Add(optiongroup);
break;
}
}
}
private void addCategories() {
List<InstallationCategory> cats =
InstallationCategory.FetchByParametersAsList(InstallationCategory.Properties.Sequence, "asc",
new BL.PropertyParameter(InstallationCategory.Properties.NetworkID, NetworkID),
new BL.PropertyParameter(InstallationCategory.Properties.Active, true));
foreach (InstallationCategory category in cats) {
// get the brands for the cat
List<InstallationBrand> brands = InstallationBrand.FetchByParametersAsList(
InstallationBrand.Properties.Sequence, "asc",
new BL.PropertyParameter(InstallationBrand.Properties.InstallationCategoryID, category.UniqueId),
new BL.PropertyParameter(InstallationBrand.Properties.Active, true));
if (brands.Count > 0) {
WC.Panel wrapper = new System.Web.UI.WebControls.Panel();
wrapper.CssClass = "contentwrap";
wrapper.ID = "wrap" + category.UniqueId.ToString();
//cat
WC.Panel pnlTitle = new WC.Panel();
pnlTitle.CssClass = "CollapseHeader";
pnlTitle.ID = "cat" + category.UniqueId.ToString();
pnlTitle.Controls.Add(new LiteralControl(category.TranslateCategoryName(Promex.Casius.Common.Translation.getLanguage())));
wrapper.Controls.Add(pnlTitle);
//brands
WC.Panel pnlDetail = new WC.Panel();
pnlDetail.CssClass = "CollapseBody";
pnlDetail.ID = category.UniqueId.ToString();
pnlDetail.Attributes.Add("rel", "checklist");
//add the brands to the cat list
foreach (InstallationBrand brand in brands) {
CheckTextBox ctb = new CheckTextBox(brand, "Eur");
pnlDetail.Controls.Add(ctb);
}
wrapper.Controls.Add(pnlDetail);
AjaxControlToolkit.CollapsiblePanelExtender cpeCollapse = new AjaxControlToolkit.CollapsiblePanelExtender();
cpeCollapse.ID = "cpe" + category.UniqueId.ToString();
cpeCollapse.TargetControlID = pnlDetail.ID;
cpeCollapse.ExpandControlID = pnlTitle.ID;
cpeCollapse.CollapseControlID = pnlTitle.ID;
if (category.DefaultMode.Equals("none")) cpeCollapse.Collapsed = true;
cpeCollapse.SuppressPostBack = true;
wrapper.Controls.Add(cpeCollapse);
this.Controls.Add(wrapper);
}
}
}
protected void submitbutton_Click(object sender, EventArgs e) {
if (Page.IsValid) {
// get the project details + project answers + total cost
List<InstallationDetail> detailList = new List<InstallationDetail>();
List<InstallationProjectAnswer> answerList = new List<InstallationProjectAnswer>();
String checkedCategoryID = String.Empty;
decimal? installationPrice = 0;
foreach (Control ctrl in this.Controls) {
// get details
if (ctrl.ID != null && ctrl.ID.StartsWith("wrap")) {
string categoryID = ctrl.ID.Replace("wrap", String.Empty);
foreach (Control chk in ctrl.FindControl(categoryID).Controls) {
if (chk is CheckTextBox && ((CheckTextBox)chk).Checked) {
InstallationDetail detail = new InstallationDetail();
detail.InstallationBrandID = Convert.ToDecimal(chk.ID.Replace("icb_", String.Empty));
detail.Price = ((CheckTextBox)chk).Cost;
detail.Quantity = (short)((CheckTextBox)chk).Quantity;
detailList.Add(detail);
checkedCategoryID = categoryID;
installationPrice += detail.Price * detail.Quantity;
}
}
}
// get answers
else if (ctrl.ID != null && ctrl.ID.StartsWith("answer")) {
//InstallationProjectAnswer answer = new InstallationProjectAnswer();
//answer.QuestionAnswerID = Convert.ToDecimal(ctrl.ID.Replace("answer", String.Empty));
//switch (ctrl.GetType().Name) {
// case "CheckboxList":
// foreach (System.Web.UI.WebControls.ListItem item in ((Promex.Casius.Common.Controls.CheckboxList)ctrl).Items) {
// if (item.Selected == true) {
// answer.AnswerCode = item.Value;
// answerList.Add(answer);
// }
// }
// break;
// case "RadioButtonList":
// answer.AnswerCode = ((Promex.Casius.Common.Controls.RadioButtonList)ctrl).SelectedValue;
// answerList.Add(answer);
// break;
// case "DropDownList":
// answer.AnswerCode = ((Promex.Casius.Common.Controls.DropDownList)ctrl).SelectedValue;
// answerList.Add(answer);
// break;
// case "TextBox":
// answer.AnswerCode = ((System.Web.UI.WebControls.TextBox)ctrl).Text;
// answerList.Add(answer);
// break;
//}
if (ctrl is Promex.Casius.Common.Controls.CheckboxList) {
foreach (System.Web.UI.WebControls.ListItem item in ((Promex.Casius.Common.Controls.CheckboxList)ctrl).Items) {
if (item.Selected == true) {
InstallationProjectAnswer answer2 = new InstallationProjectAnswer();
answer2.QuestionAnswerID = Convert.ToDecimal(ctrl.ID.Replace("answer", String.Empty));
answer2.AnswerCode = item.Value;
answerList.Add(answer2);
}
}
} else if (ctrl is Promex.Casius.Common.Controls.RadioButtonList) {
InstallationProjectAnswer answer2 = new InstallationProjectAnswer();
answer2.QuestionAnswerID = Convert.ToDecimal(ctrl.ID.Replace("answer", String.Empty));
answer2.AnswerCode = ((Promex.Casius.Common.Controls.RadioButtonList)ctrl).SelectedValue;
answerList.Add(answer2);
} else if (ctrl is Promex.Casius.Common.Controls.DropDownList) {
InstallationProjectAnswer answer2 = new InstallationProjectAnswer();
answer2.QuestionAnswerID = Convert.ToDecimal(ctrl.ID.Replace("answer", String.Empty));
answer2.AnswerCode = ((Promex.Casius.Common.Controls.DropDownList)ctrl).SelectedValue;
answerList.Add(answer2);
} else if (ctrl is System.Web.UI.WebControls.TextBox) {
InstallationProjectAnswer answer2 = new InstallationProjectAnswer();
answer2.QuestionAnswerID = Convert.ToDecimal(ctrl.ID.Replace("answer", String.Empty));
answer2.AnswerCode = ((System.Web.UI.WebControls.TextBox)ctrl).Text;
answerList.Add(answer2);
}
}
}
//add default costs to total
//calculate singleCost
decimal NetworkID = (decimal)HttpContext.Current.Session[SessionProperty.AffNetworkID.ToString()];
List<NetworkPrice> networkPrices = NetworkPrice.FetchByParametersAsList(new PropertyParameter("NetworkID", NetworkID));
float singleCost = 0;
float prevPrice = 0;
foreach (NetworkPrice networkPrice in networkPrices) {
// calculate singlePrice
if (networkPrices.IndexOf(networkPrice) == 0) {
if (installationPrice < (int)networkPrice.InstallationMaximumPrice) {
singleCost = networkPrice.VariablePrice;
continue;
}
} else if (networkPrices.IndexOf(networkPrice) < (networkPrices.Count - 1)) {
if (installationPrice >= (int)prevPrice && installationPrice < (int)networkPrice.InstallationMaximumPrice) {
singleCost = networkPrice.VariablePrice;
continue;
}
} else {
if (installationPrice >= (int)prevPrice) {
singleCost = networkPrice.VariablePrice;
continue;
}
}
prevPrice = networkPrice.InstallationMaximumPrice;
}
//Calculate total
float InstallationTotal = (int)singleCost + (int)installationPrice;
//save the project
InstallationProject project = new InstallationProject();
DateTime now = DateTime.Now;
project.AffiliateID = (int)HttpContext.Current.Session[SessionProperty.AffID.ToString()];
project.NetworkID = NetworkID;
project.DateTimeStamp = now;
project.Status = "00";
project.StatusDate = now;
project.TotalCost = (int)InstallationTotal;
string comment = ((WC.TextBox)this.FindControl("comment")).Text;
if (comment.Length > 512)
comment = comment.Substring(0, 511);
project.UserComment = comment;
project.Save();
//save the details + answers
foreach (InstallationDetail detail in detailList) {
detail.InstallationProjectID = project.UniqueId;
detail.Save();
}
foreach (InstallationProjectAnswer answer in answerList) {
answer.InstallationProjectID = project.UniqueId;
answer.Save();
}
HttpContext.Current.Session[SessionProperty.InstallationIntakeProjectID.ToString()] = project.UniqueId.ToString();
HttpContext.Current.Session[SessionProperty.InstallationIntakeCategoryID.ToString()] = checkedCategoryID.ToString();
HttpContext.Current.Session[SessionProperty.AllowRegistration.ToString()] = true;
if (User.GetCurrent() != null) {
Logging.WriteToLog("Redirect", "redirecting to :" + umbraco.library.NiceUrl(redirectToSummary));
Logging.WriteToLog("Redirect", "User :" + User.GetCurrent().FirstName + " " + User.GetCurrent().LastName);
HttpContext.Current.Response.Redirect(umbraco.library.NiceUrl(redirectToSummary));
} else {
Logging.WriteToLog("Redirect", "redirecting to :" + umbraco.library.NiceUrl(redirectForLogin));
HttpContext.Current.Response.Redirect(umbraco.library.NiceUrl(redirectForLogin));
}
}
}
public int redirectForLogin {
get;
set;
}
public int redirectToSummary {
get;
set;
}
}
}
It's probably because your instantiating your variables from casted Session variables, without any sort of error checking.
For example
Try adding the control directly to the page and not through a macro. This should give you a more infomative error.
That did the trick,
I addedd empty class variables and filled them OnLoad() with the Session data.
It seems like asp does'nt know anything of the session before initialization.
Anyway, it works now.
Thanks alot.
is working on a reply...