private void AddTextBoxValidator(webforms_sheetfielddef sfd) { String FieldName = sfd.FieldName; String ErrorMessage = ""; if (FieldName.ToLower() == "fname" || FieldName.ToLower() == "firstname") { ErrorMessage = "First Name is a required field"; } else if (FieldName.ToLower() == "lname" || FieldName.ToLower() == "lastname") { ErrorMessage = "Last Name is a required field"; } else if (FieldName.ToLower() == "birthdate" || FieldName.ToLower() == "bdate") { ErrorMessage = "Birthdate is a required field"; } else if (sfd.IsRequired == (sbyte)1) { ErrorMessage = "This is a required field"; } else { return; } // required field validator RequiredFieldValidator rv = new RequiredFieldValidator(); rv.ControlToValidate = "" + sfd.WebSheetFieldDefID; rv.ErrorMessage = ErrorMessage; rv.Display = ValidatorDisplay.None; rv.SetFocusOnError = true; rv.ID = "RequiredFieldValidator" + rv.ControlToValidate; Panel1.Controls.Add(rv); //callout extender AjaxControlToolkit.ValidatorCalloutExtender vc = new AjaxControlToolkit.ValidatorCalloutExtender(); vc.TargetControlID = rv.ID; vc.ID = "ValidatorCalloutExtender" + rv.ID; Panel1.Controls.Add(vc); if (FieldName.ToLower() == "birthdate" || FieldName.ToLower() == "bdate") { //compare validator CompareValidator cv = new CompareValidator(); cv.ControlToValidate = "" + sfd.WebSheetFieldDefID; cv.ErrorMessage = "Invalid Date of Birth."; cv.Display = ValidatorDisplay.None; cv.Type = ValidationDataType.Date; cv.Operator = ValidationCompareOperator.DataTypeCheck; cv.SetFocusOnError = true; cv.ID = "CompareValidator" + cv.ControlToValidate; //callout extender AjaxControlToolkit.ValidatorCalloutExtender vc1 = new AjaxControlToolkit.ValidatorCalloutExtender(); vc1.TargetControlID = cv.ID; vc1.ID = "ValidatorCalloutExtender" + cv.ID; Panel1.Controls.Add(cv); Panel1.Controls.Add(vc1); } }
private WebControl AddCheckBox(webforms_sheetfielddef sfd) { WebControl wc = null; CheckBox cb = new CheckBox(); cb.ID = "" + sfd.WebSheetFieldDefID; AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender mecb = new AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender(); mecb.ID = cb.ID + "MutuallyExclusiveCheckBoxExtender"; mecb.TargetControlID = cb.ID; mecb.Key = GetChkBoxGroupName(sfd); Panel1.Controls.Add(mecb); wc = cb; return(wc); }
/// <summary> /// All checkboxes that require validation are stored in the format: /// key=hiddenChkBoxGroup+(ChkBoxGroupName) and value= "chkbxid1 chkbxid1 chkbxid1" /// </summary> private void AddChkBoxIdsToHashTable(webforms_sheetfielddef sfd) { String ChkBoxGroupName = GetChkBoxGroupName(sfd); String Key = "hiddenChkBoxGroup" + ChkBoxGroupName; String Value = "" + sfd.WebSheetFieldDefID; if (hiddenChkBoxGroupHashTable.ContainsKey(Key)) { hiddenChkBoxGroupHashTable[Key] += " " + Value; } else { hiddenChkBoxGroupHashTable.Add(Key, Value); } }
private string GetChkBoxGroupName(webforms_sheetfielddef sfd) { String FieldName = sfd.FieldName; String RadioButtonValue = sfd.RadioButtonValue; String RadioButtonGroup = sfd.RadioButtonGroup; String ChkBoxGroupName = null; if (!String.IsNullOrEmpty(RadioButtonGroup) && FieldName == "misc") { ChkBoxGroupName = RadioButtonGroup; } else if (!String.IsNullOrEmpty(RadioButtonValue)) // cases like gender, position etc that have no value for RadioButtonGroup but have RadioButtonValue { ChkBoxGroupName = FieldName; } return(ChkBoxGroupName); }
private void AddRequiredChkBoxValidator(webforms_sheetfielddef sfd, float CheckBoxXOffset, float CheckBoxYOffset) { if (sfd.IsRequired != (sbyte)1) { return; } int XPosErrorMessageOffset = 2; int XPos = sfd.XPos; int YPos = sfd.YPos; String ErrorMessage = "This is a required section. Please check one of the Check Boxes"; //add dummy textbox to get around the limitation of checkboxes not having validators and call outs. TextBox tb = new TextBox(); tb.Rows = 1; tb.Text = ".";// there has to be some character here the least visible is the period. tb.MaxLength = 1; tb.Width = Unit.Pixel(1); tb.ID = "TextBoxForCheckbox" + sfd.WebSheetFieldDefID; tb.Style["position"] = "absolute"; tb.Style["top"] = YPos + CheckBoxYOffset + "px"; tb.Style["left"] = XPos + CheckBoxXOffset + XPosErrorMessageOffset + sfd.Width + "px"; tb.Style["z-index"] = "-2"; tb.ReadOnly = true; tb.BorderWidth = Unit.Pixel(0); Panel1.Controls.Add(tb); CustomValidator cv = new CustomValidator(); cv.ControlToValidate = tb.ID; cv.ErrorMessage = ErrorMessage; cv.Display = ValidatorDisplay.None; cv.SetFocusOnError = true; cv.ID = "CustomValidator" + cv.ControlToValidate; cv.ClientValidationFunction = "CheckCheckBoxes"; Panel1.Controls.Add(cv); //callout extender AjaxControlToolkit.ValidatorCalloutExtender vc = new AjaxControlToolkit.ValidatorCalloutExtender(); vc.TargetControlID = cv.ID; vc.ID = "ValidatorCalloutExtender" + cv.ID; Panel1.Controls.Add(vc); AddChkBoxIdsToHashTable(sfd); }
private void FillFieldSheetDef(SheetDef sheetDef, webforms_sheetdef SheetDefObj) { for (int i = 0; i < sheetDef.SheetFieldDefs.Count(); i++) //assign several webforms_sheetfielddef { webforms_sheetfielddef SheetFieldDefObj = new webforms_sheetfielddef(); SheetDefObj.webforms_sheetfielddef.Add(SheetFieldDefObj); // assign each property of a single webforms_sheetfielddef with corresponding values. foreach (FieldInfo fieldinfo in sheetDef.SheetFieldDefs[i].GetType().GetFields()) { foreach (PropertyInfo propertyinfo in SheetFieldDefObj.GetType().GetProperties()) { if (fieldinfo.Name == propertyinfo.Name) { if (propertyinfo.PropertyType == typeof(SByte)) { if ((bool)fieldinfo.GetValue(sheetDef.SheetFieldDefs[i]) == true) { propertyinfo.SetValue(SheetFieldDefObj, (sbyte)1, null); } else { propertyinfo.SetValue(SheetFieldDefObj, (sbyte)0, null); } } else { if (fieldinfo.GetValue(sheetDef.SheetFieldDefs[i]) == null) { propertyinfo.SetValue(SheetFieldDefObj, "", null); } else { propertyinfo.SetValue(SheetFieldDefObj, fieldinfo.GetValue(sheetDef.SheetFieldDefs[i]), null); } } } } //foreach propertyinfo } //foreach fieldinfo } }