/projects/PigeonCms.Core/Helpers/FormsBuilder.cs

http://pigeoncms.googlecode.com/ · C# · 804 lines · 645 code · 71 blank · 88 comment · 85 complexity · 59953ab14c50650639688afe7d5edd23 MD5 · raw file

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Diagnostics;
  11. using System.ComponentModel;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using PigeonCms;
  15. using System.Xml;
  16. using System.Reflection;
  17. using System.Web.Compilation;
  18. using FredCK.FCKeditorV2;
  19. namespace PigeonCms
  20. {
  21. public enum FormFieldTypeEnum
  22. {
  23. Text = 0,
  24. List,
  25. Combo,
  26. Radio,
  27. Check,
  28. Calendar,
  29. Custom,
  30. Spacer,
  31. Hidden,
  32. Error,
  33. Html
  34. }
  35. public class FormFieldOption
  36. {
  37. private string label = "";
  38. private string value = "";
  39. public FormFieldOption(string label, string value)
  40. {
  41. this.label = label;
  42. this.value = value;
  43. }
  44. public string Label
  45. {
  46. [DebuggerStepThrough()]
  47. get { return label; }
  48. [DebuggerStepThrough()]
  49. set { label = value; }
  50. }
  51. public string Value
  52. {
  53. [DebuggerStepThrough()]
  54. get { return this.value; }
  55. [DebuggerStepThrough()]
  56. set { this.value = value; }
  57. }
  58. }
  59. [DebuggerDisplay("Name={name}, DefaultValue={defaultValue}, Type={type}")]
  60. public class FormField
  61. {
  62. string group = "";
  63. string name = "";
  64. string defaultValue = "";
  65. int rows = 0;
  66. int cols = 0;
  67. string labelValue = "";
  68. string description = "";
  69. string cssClass = "";
  70. string cssStyle = "";
  71. List<FormFieldOption> options = new List<FormFieldOption>();
  72. FormFieldTypeEnum type = FormFieldTypeEnum.Text;
  73. public FormField(){}
  74. public string Group
  75. {
  76. [DebuggerStepThrough()]
  77. get { return group; }
  78. [DebuggerStepThrough()]
  79. set { group = value; }
  80. }
  81. public string Name
  82. {
  83. [DebuggerStepThrough()]
  84. get { return name; }
  85. [DebuggerStepThrough()]
  86. set { name = value; }
  87. }
  88. public string DefaultValue
  89. {
  90. [DebuggerStepThrough()]
  91. get { return defaultValue; }
  92. [DebuggerStepThrough()]
  93. set { defaultValue = value; }
  94. }
  95. public int Rows
  96. {
  97. [DebuggerStepThrough()]
  98. get { return rows; }
  99. [DebuggerStepThrough()]
  100. set { rows = value; }
  101. }
  102. public int Cols
  103. {
  104. [DebuggerStepThrough()]
  105. get { return cols; }
  106. [DebuggerStepThrough()]
  107. set { cols = value; }
  108. }
  109. public string LabelValue
  110. {
  111. [DebuggerStepThrough()]
  112. get { return labelValue; }
  113. [DebuggerStepThrough()]
  114. set { labelValue = value; }
  115. }
  116. public string Description
  117. {
  118. [DebuggerStepThrough()]
  119. get { return description; }
  120. [DebuggerStepThrough()]
  121. set { description = value; }
  122. }
  123. public string CssClass
  124. {
  125. [DebuggerStepThrough()]
  126. get { return cssClass; }
  127. [DebuggerStepThrough()]
  128. set { cssClass = value; }
  129. }
  130. public string CssStyle
  131. {
  132. [DebuggerStepThrough()]
  133. get { return cssStyle; }
  134. [DebuggerStepThrough()]
  135. set { cssStyle = value; }
  136. }
  137. public List<FormFieldOption> Options
  138. {
  139. [DebuggerStepThrough()]
  140. get { return options; }
  141. [DebuggerStepThrough()]
  142. set { options = value; }
  143. }
  144. public FormFieldTypeEnum Type
  145. {
  146. [DebuggerStepThrough()]
  147. get { return type; }
  148. [DebuggerStepThrough()]
  149. set { type = value; }
  150. }
  151. }
  152. /// <summary>
  153. /// static class with methods to help controls rendering, controls reading, etc..
  154. /// </summary>
  155. public static class FormBuilder
  156. {
  157. #region public methods
  158. public static Control RenderControl(FormField field, string currentValue)
  159. {
  160. return RenderControl(field, currentValue, "");
  161. }
  162. /// <summary>
  163. /// render the aspnet control parsing param, to admin module
  164. /// </summary>
  165. /// <param name="field"></param>
  166. /// <param name="currentValue"></param>
  167. /// <param name="defaultCssClass"></param>
  168. /// <returns></returns>
  169. public static Control RenderControl(FormField field, string currentValue, string defaultCssClass)
  170. {
  171. Control result = null;
  172. switch (field.Type)
  173. {
  174. case FormFieldTypeEnum.Text:
  175. result = (Control)getTextControl(field, currentValue, defaultCssClass);
  176. break;
  177. case FormFieldTypeEnum.List:
  178. result = (Control)getHiddenControl(field, currentValue); //TODO
  179. //result = (Control)getListControl(param, currentValue);
  180. break;
  181. case FormFieldTypeEnum.Combo:
  182. result = (Control)getComboControl(field, currentValue, defaultCssClass);
  183. break;
  184. case FormFieldTypeEnum.Radio:
  185. result = (Control)getHiddenControl(field, currentValue); //TODO
  186. break;
  187. case FormFieldTypeEnum.Check:
  188. result = (Control)getHiddenControl(field, currentValue); //TODO
  189. break;
  190. case FormFieldTypeEnum.Calendar:
  191. result = (Control)getHiddenControl(field, currentValue); //TODO
  192. break;
  193. case FormFieldTypeEnum.Custom:
  194. result = (Control)getHiddenControl(field, currentValue); //TODO
  195. break;
  196. case FormFieldTypeEnum.Spacer:
  197. result = (Control)getSpacerControl(field, currentValue);
  198. break;
  199. case FormFieldTypeEnum.Hidden:
  200. result = (Control)getHiddenControl(field, currentValue);
  201. break;
  202. case FormFieldTypeEnum.Error:
  203. result = (Control)getHiddenControl(field, currentValue); //todo
  204. break;
  205. case FormFieldTypeEnum.Html:
  206. result = (Control)getHtmlControl(field, currentValue, defaultCssClass);
  207. break;
  208. default:
  209. break;
  210. }
  211. return result;
  212. }
  213. /// <summary>
  214. /// render the html controls on panel
  215. /// </summary>
  216. /// <param name="panel">the container for generated controls</param>
  217. /// <param name="currentItem">current Item</param>
  218. public static void RenderParamsOnPanel(Panel panel, Item currentItem, List<ResLabel> labelsList)
  219. {
  220. PigeonCms.ItemType itemType = null;
  221. Dictionary<string, string> fieldsValues = new Dictionary<string,string>();
  222. PropertyInfo pi = null;
  223. Type type = null;
  224. try
  225. {
  226. type = BuildManager.GetType(currentItem.ItemTypeName, false);
  227. itemType = currentItem.ItemType;
  228. foreach (FormField currParam in itemType.Fields)
  229. {
  230. object value = null;
  231. string baseClassFieldName = "";
  232. pi = type.GetProperty(currParam.Name); //inerithed class field
  233. if (pi != null)
  234. {
  235. foreach (ItemFieldMapAttribute attr in pi.GetCustomAttributes(typeof(ItemFieldMapAttribute), false))
  236. {
  237. if (attr != null)
  238. {
  239. baseClassFieldName = attr.FieldName.ToString(); //base class mapped field
  240. break;
  241. }
  242. }
  243. }
  244. if (!string.IsNullOrEmpty(baseClassFieldName))
  245. {
  246. pi = type.GetProperty(baseClassFieldName); //base class field
  247. if (pi != null)
  248. {
  249. value = pi.GetValue(currentItem, null);
  250. if (value != null)
  251. fieldsValues.Add(currParam.Name, value.ToString());
  252. }
  253. }
  254. }
  255. RenderParamsOnPanel(panel, fieldsValues, itemType.Fields, labelsList);
  256. }
  257. catch (Exception ex)
  258. {
  259. Tracer.Log("RenderParamsOnPanel(): error loading item fields", TracerItemType.Error, ex);
  260. }
  261. }
  262. /// <summary>
  263. /// render the html controls on panel
  264. /// </summary>
  265. /// <param name="panel">the container for generated controls</param>
  266. /// <param name="fieldsValues">list of params keys and values</param>
  267. /// <param name="fieldsList">fields list for the current item (from xml file)</param>
  268. public static void RenderParamsOnPanel(Panel panel, Dictionary<string, string> fieldsValues,
  269. List<FormField> fieldsList, List<ResLabel> labelsList)
  270. {
  271. string currGroup = "not set"; //current param group label
  272. HtmlTable tableParams = null; //render table
  273. //clear previous params list
  274. while (panel.Controls.Count > 0)
  275. {
  276. panel.Controls.RemoveAt(0);
  277. }
  278. foreach (FormField currParam in fieldsList)
  279. {
  280. //add a pane foreach different param group
  281. if (currParam.Group != currGroup)
  282. {
  283. currGroup = currParam.Group;
  284. Literal litGroupName = new Literal();
  285. if (string.IsNullOrEmpty(currParam.Group))
  286. {
  287. //litGroupName.Text = Utility.GetLabel("LblModule");
  288. }
  289. else
  290. {
  291. litGroupName.Text = currParam.Group;
  292. }
  293. panel.Controls.Add(litGroupName);
  294. tableParams = createTable(tableParams);
  295. panel.Controls.Add(tableParams);
  296. }
  297. //add params to current pane
  298. Control control2Add = null;
  299. try
  300. {
  301. string currentValue = "";
  302. if (fieldsValues.ContainsKey(currParam.Name))
  303. {
  304. currentValue = fieldsValues[currParam.Name];
  305. }
  306. control2Add = FormBuilder.RenderControl(currParam, currentValue, "adminMediumText");
  307. }
  308. catch (Exception)
  309. { }
  310. finally
  311. {
  312. if (control2Add == null)
  313. {
  314. Literal litErrorParsing = new Literal();
  315. litErrorParsing.Text = Utility.GetErrorLabel("ParamParsing", "Error parsing [" + currParam.Name + "] param");
  316. control2Add = (Control)litErrorParsing;
  317. }
  318. }
  319. addTableRow(tableParams, currParam, control2Add, labelsList);
  320. }
  321. }
  322. /// <summary>
  323. /// Get the string with params value to store in db reading controls inside container
  324. /// </summary>
  325. /// <param name="moduleParams">list of moduleParam</param>
  326. /// <param name="container">the parent control</param>
  327. /// <returns>the moduleParams string</returns>
  328. public static string GetParamsString(List<FormField> formFieldList, Control container)
  329. {
  330. string res = "";
  331. string currValue = "";
  332. foreach (FormField currField in formFieldList)
  333. {
  334. currValue = "";
  335. #warning to complete GetModuleParamsString
  336. switch (currField.Type)
  337. {
  338. case FormFieldTypeEnum.Text:
  339. {
  340. TextBox t1 = new TextBox();
  341. t1 = Utility.FindControlRecursive<TextBox>(container, t1.GetType().Name + currField.Name);
  342. if (t1 != null)
  343. {
  344. currValue = t1.Text;
  345. }
  346. }
  347. break;
  348. case FormFieldTypeEnum.Html:
  349. {
  350. FCKeditor t1 = new FCKeditor();
  351. t1 = Utility.FindControlRecursive<FCKeditor>(container, t1.GetType().Name + currField.Name);
  352. if (t1 != null)
  353. {
  354. currValue = t1.Value;
  355. }
  356. }
  357. break;
  358. case FormFieldTypeEnum.Combo:
  359. {
  360. DropDownList t1 = new DropDownList();
  361. t1 = Utility.FindControlRecursive<DropDownList>(container, t1.GetType().Name + currField.Name);
  362. if (t1 != null)
  363. {
  364. currValue = t1.SelectedValue;
  365. }
  366. }
  367. break;
  368. case FormFieldTypeEnum.Hidden:
  369. case FormFieldTypeEnum.Error:
  370. {
  371. HiddenField t1 = new HiddenField();
  372. t1 = Utility.FindControlRecursive<HiddenField>(container, t1.GetType().Name + currField.Name);
  373. if (t1 != null)
  374. {
  375. currValue = t1.Value;
  376. }
  377. }
  378. break;
  379. }
  380. if (!string.IsNullOrEmpty(currField.Name))
  381. {
  382. res += currField.Name + ":=" + currValue + "|";
  383. }
  384. }
  385. if (res.Length > 1)
  386. {
  387. if (res[res.Length - 1] == '|')
  388. {
  389. res = res.Substring(0, res.Length - 1);
  390. }
  391. }
  392. return res;
  393. }
  394. public static FormField GetFormFieldFromXmlNode(XmlNode nodeParam, XmlNode nodeParams)
  395. {
  396. FormField item = new FormField();
  397. try
  398. {
  399. item.Type = (FormFieldTypeEnum)Enum.Parse(
  400. typeof(FormFieldTypeEnum),
  401. nodeParam.Attributes["type"].Value, true);
  402. }
  403. catch (Exception)
  404. {
  405. item.Type = FormFieldTypeEnum.Error;
  406. }
  407. if (nodeParam.Attributes["name"] != null)
  408. {
  409. item.Name = nodeParam.Attributes["name"].Value;
  410. }
  411. if (nodeParam.Attributes["default"] != null)
  412. {
  413. item.DefaultValue = nodeParam.Attributes["default"].Value;
  414. }
  415. if (nodeParam.Attributes["rows"] != null)
  416. {
  417. int value = 0;
  418. int.TryParse(nodeParam.Attributes["rows"].Value, out value);
  419. item.Rows = value;
  420. }
  421. if (nodeParam.Attributes["cols"] != null)
  422. {
  423. int value = 0;
  424. int.TryParse(nodeParam.Attributes["cols"].Value, out value);
  425. item.Cols = value;
  426. }
  427. if (nodeParam.Attributes["label"] != null)
  428. {
  429. item.LabelValue = nodeParam.Attributes["label"].Value;
  430. }
  431. if (nodeParam.Attributes["description"] != null)
  432. {
  433. item.Description = nodeParam.Attributes["description"].Value;
  434. }
  435. if (nodeParam.Attributes["cssStyle"] != null)
  436. {
  437. item.CssStyle = nodeParam.Attributes["cssStyle"].Value;
  438. }
  439. if (nodeParam.Attributes["cssClass"] != null)
  440. {
  441. item.CssClass = nodeParam.Attributes["cssClass"].Value;
  442. }
  443. if (nodeParams.Attributes["group"] != null)
  444. {
  445. item.Group = nodeParams.Attributes["group"].Value;
  446. }
  447. //options list
  448. XmlNodeList optionsList = nodeParam.SelectNodes("option");
  449. foreach (XmlNode nodeOption in optionsList)
  450. {
  451. string label = "";
  452. string value = "";
  453. if (nodeOption.Attributes["label"] != null)
  454. {
  455. label = nodeOption.Attributes["label"].Value;
  456. }
  457. if (nodeOption.Attributes["value"] != null)
  458. {
  459. value = nodeOption.Attributes["value"].Value;
  460. }
  461. item.Options.Add(new FormFieldOption(label, value));
  462. }
  463. //other options from datasource list
  464. XmlNodeList dsList = nodeParam.SelectNodes("datasource");
  465. foreach (XmlNode ds in dsList)
  466. {
  467. try
  468. {
  469. parseTagDatasource(ds, item);
  470. }
  471. catch (Exception ex)
  472. {
  473. throw new ArgumentException(
  474. "Parsing field " + item.Name + " datasource typename ", ex);
  475. }
  476. }
  477. //other options from enum datasource list
  478. XmlNodeList enumList = nodeParam.SelectNodes("enum");
  479. foreach (XmlNode ds in enumList)
  480. {
  481. try
  482. {
  483. parseTagEnum(ds, item);
  484. }
  485. catch (Exception ex)
  486. {
  487. throw new ArgumentException(
  488. "Parsing field " + item.Name + " enum typename ", ex);
  489. }
  490. }
  491. return item;
  492. }
  493. #endregion
  494. #region private methods
  495. private static Literal getSpacerControl(FormField param, string currentValue)
  496. {
  497. Literal ctrl = new Literal();
  498. //ctrl.ID = ctrl.GetType().ToString() + param.Name;
  499. if (currentValue == null)
  500. ctrl.Text = param.DefaultValue;
  501. else
  502. ctrl.Text = currentValue;
  503. return ctrl;
  504. }
  505. private static TextBox getTextControl(FormField param, string currentValue)
  506. {
  507. return getTextControl(param, currentValue, "");
  508. }
  509. private static TextBox getTextControl(FormField param, string currentValue, string defaultCssClass)
  510. {
  511. TextBox ctrl = new TextBox();
  512. ctrl.ID = ctrl.GetType().Name + param.Name;
  513. ctrl.ToolTip = param.Description;
  514. ctrl.Style.Value = param.CssStyle;
  515. if (!string.IsNullOrEmpty(param.CssClass))
  516. ctrl.CssClass = param.CssClass;
  517. else
  518. ctrl.CssClass = defaultCssClass;//"adminMediumText";
  519. if (string.IsNullOrEmpty(currentValue))
  520. ctrl.Text = param.DefaultValue;
  521. else
  522. ctrl.Text = currentValue;
  523. if (param.Rows > 0) //textarea
  524. {
  525. ctrl.TextMode = TextBoxMode.MultiLine;
  526. ctrl.Rows = param.Rows;
  527. if (param.Cols > 0) ctrl.Columns = param.Cols;
  528. }
  529. //txt1.MaxLength = 50;
  530. //txt1.Width = new Unit(255);
  531. return ctrl;
  532. }
  533. private static FCKeditor getHtmlControl(FormField param, string currentValue)
  534. {
  535. return getHtmlControl(param, currentValue, "");
  536. }
  537. private static FCKeditor getHtmlControl(FormField param, string currentValue, string defaultCssClass)
  538. {
  539. FCKeditor ctrl = new FCKeditor();
  540. ctrl.ID = ctrl.GetType().Name + param.Name;
  541. ctrl.ToolbarStartExpanded = false;
  542. ctrl.ToolbarSet = "Basic";
  543. //if (!string.IsNullOrEmpty(param.CssClass))
  544. // ctrl.EditorAreaCSS = param.CssClass;
  545. //else
  546. // ctrl.EditorAreaCSS = defaultCssClass;//"adminMediumText";
  547. if (string.IsNullOrEmpty(currentValue))
  548. ctrl.Value = param.DefaultValue;
  549. else
  550. ctrl.Value = currentValue;
  551. if (param.Rows > 0)
  552. ctrl.Height = new Unit(100 * param.Rows);
  553. if (param.Cols > 0)
  554. ctrl.Width = new Unit(10 * param.Cols);
  555. return ctrl;
  556. }
  557. private static DropDownList getComboControl(FormField param, string currentValue)
  558. {
  559. return getComboControl(param, currentValue, "");
  560. }
  561. private static DropDownList getComboControl(FormField param, string currentValue, string defaultCssClass)
  562. {
  563. DropDownList ctrl = new DropDownList();
  564. ctrl.ID = ctrl.GetType().Name + param.Name;
  565. ctrl.ToolTip = param.Description;
  566. ctrl.Style.Value = param.CssStyle;
  567. if (!string.IsNullOrEmpty(param.CssClass))
  568. ctrl.CssClass = param.CssClass;
  569. else
  570. ctrl.CssClass = defaultCssClass;//"adminMediumText";
  571. foreach (FormFieldOption item in param.Options)
  572. {
  573. ctrl.Items.Add(new ListItem(item.Label, item.Value));
  574. if (string.IsNullOrEmpty(currentValue))
  575. {
  576. if (ctrl.Items[ctrl.Items.Count - 1].Value == param.DefaultValue)
  577. ctrl.Items[ctrl.Items.Count - 1].Selected = true;
  578. }
  579. else
  580. {
  581. if (ctrl.Items[ctrl.Items.Count - 1].Value == currentValue)
  582. ctrl.Items[ctrl.Items.Count - 1].Selected = true;
  583. }
  584. }
  585. return ctrl;
  586. }
  587. private static HiddenField getHiddenControl(FormField param, string currentValue)
  588. {
  589. HiddenField ctrl = new HiddenField();
  590. ctrl.ID = ctrl.GetType().Name + param.Name;
  591. if (string.IsNullOrEmpty(currentValue))
  592. ctrl.Value = param.DefaultValue;
  593. else
  594. ctrl.Value = currentValue;
  595. return ctrl;
  596. }
  597. //private static TextBox getListControl(ModuleParam param, string currentValue)
  598. //{
  599. // ListBox ctrl = new ListBox();
  600. // ctrl.ID = ctrl.GetType().Name + param.Name;
  601. // ctrl.ToolTip = param.Description;
  602. // ctrl.CssClass = "adminMediumText";
  603. // if (currentValue == null)
  604. // ctrl.Text = param.DefaultValue;
  605. // else
  606. // ctrl.Text = currentValue;
  607. // if (param.Rows > 0) //textarea
  608. // {
  609. // ctrl.TextMode = TextBoxMode.MultiLine;
  610. // ctrl.Rows = param.Rows;
  611. // if (param.Cols > 0) ctrl.Columns = param.Cols;
  612. // }
  613. // //txt1.MaxLength = 50;
  614. // //txt1.Width = new Unit(255);
  615. // return ctrl;
  616. //}
  617. /// <summary>
  618. /// parse datasource tag
  619. /// </summary>
  620. /// <param name="nodeDatasource"></param>
  621. /// <param name="item"></param>
  622. private static void parseTagDatasource(XmlNode nodeDatasource, FormField item)
  623. {
  624. string selectMethod = "";
  625. string selectParams = "";
  626. string typeName = "";
  627. if (nodeDatasource != null)
  628. {
  629. if (nodeDatasource.Attributes["SelectMethod"] != null)
  630. {
  631. selectMethod = nodeDatasource.Attributes["SelectMethod"].Value;
  632. }
  633. if (nodeDatasource.Attributes["SelectParams"] != null)
  634. {
  635. selectParams = nodeDatasource.Attributes["SelectParams"].Value;
  636. }
  637. if (nodeDatasource.Attributes["TypeName"] != null)
  638. {
  639. typeName = nodeDatasource.Attributes["TypeName"].Value;
  640. }
  641. object obj;
  642. if (!string.IsNullOrEmpty(selectParams))
  643. {
  644. var paramsList = Utility.String2List(selectParams);
  645. object[] parameters = paramsList.ToArray();
  646. //object[] parameters = new object[0];
  647. //parameters[0] = selectParams;
  648. obj = PigeonCms.Reflection.Process(typeName, selectMethod, parameters);
  649. }
  650. else
  651. {
  652. obj = PigeonCms.Reflection.Process(typeName, selectMethod, null);
  653. }
  654. Dictionary<string, string> res = (Dictionary<string, string>)obj;
  655. foreach (KeyValuePair<string, string> pair in res)
  656. {
  657. item.Options.Add(new FormFieldOption(pair.Value, pair.Key));
  658. }
  659. }
  660. }
  661. /// <summary>
  662. /// parse enum datasource tag
  663. /// </summary>
  664. /// <param name="nodeEnum"></param>
  665. /// <param name="item"></param>
  666. private static void parseTagEnum(XmlNode nodeEnum, FormField item)
  667. {
  668. string typeName = "";
  669. if (nodeEnum != null)
  670. {
  671. if (nodeEnum.Attributes["TypeName"] != null)
  672. {
  673. typeName = nodeEnum.Attributes["TypeName"].Value;
  674. }
  675. var type = BuildManager.GetType(typeName, true);
  676. foreach (string name in Enum.GetNames(type))
  677. {
  678. int value = (int)Enum.Parse(type, name);
  679. item.Options.Add(new FormFieldOption(name, value.ToString()));
  680. }
  681. }
  682. }
  683. /// <summary>
  684. /// create the table that contains the params or views rows
  685. /// </summary>
  686. /// <param name="tableParams">HtmlTable object</param>
  687. /// <returns>HtmlTable with the right format</returns>
  688. private static HtmlTable createTable(HtmlTable table)
  689. {
  690. table = new HtmlTable();
  691. table.CellSpacing = 0;
  692. table.Attributes["class"] = "adminTable";
  693. return table;
  694. }
  695. /// <summary>
  696. /// add a row with the label and the control for the current param
  697. /// </summary>
  698. /// <param name="tableParams">table in which add the row</param>
  699. /// <param name="currParam">ModuleParam instance of the param to add</param>
  700. /// <param name="control2Add">control to add</param>
  701. private static void addTableRow(HtmlTable tableParams, FormField currParam,
  702. Control control2Add, List<ResLabel> labelsList)
  703. {
  704. HtmlTableRow row = new HtmlTableRow();
  705. HtmlTableCell cell1 = new HtmlTableCell();
  706. HtmlTableCell cell2 = new HtmlTableCell();
  707. Literal litParamError = new Literal();
  708. Label lblParamLabel = new Label();
  709. //litParamLabel.Text = "<label for='"+ control2Add.ClientID +"' title='"+ currParam.Description +"'>"+ currParam.LabelValue + "</label>";
  710. lblParamLabel.Text = LabelsProvider.GetLocalizedVarFromList(labelsList, currParam.LabelValue); //currParam.LabelValue;
  711. lblParamLabel.ToolTip = LabelsProvider.GetLocalizedVarFromList(labelsList, currParam.Description); //currParam.Description;
  712. lblParamLabel.AssociatedControlID = control2Add.ClientID;
  713. cell1.Attributes["class"] = "key";
  714. cell1.Controls.Add(lblParamLabel);
  715. cell2.Controls.Add(control2Add);
  716. if (currParam.Type == FormFieldTypeEnum.Error)
  717. {
  718. litParamError.Text = Utility.GetLabel("ErrParamParsing", "Error parsing [" + currParam.Name + "] param");
  719. cell2.Controls.Add(litParamError);
  720. //and add an hidden control
  721. }
  722. if (currParam.Type == FormFieldTypeEnum.Hidden)
  723. {
  724. //if hidden param hide row
  725. row.Style["display"] = "none";
  726. }
  727. row.Cells.Add(cell1);
  728. row.Cells.Add(cell2);
  729. tableParams.Rows.Add(row);
  730. }
  731. #endregion
  732. }
  733. }