예제 #1
0
 /// <summary>
 /// Creates a checkbox input. It correctly deals with the issue related to the false value of a checkbox not being sent to the client 
 /// </summary>
 /// <param name="name">The value to assign to the input as the name and id</param>
 /// <param name="id">The ID to assign to the element</param>
 /// <param name="value">The value of the checkbox</param>
 /// <param name="cssclass">The CSS class to assign to the checkbox</param>
 /// <param name="label">The label to include the checkbox</param>
 /// <param name="labelCssClass">The CSS class to assign to the label</param>
 /// <param name="tabIndex">The tabIndex if any to assign to the checkbox</param>
 /// <returns>A string with the html for the checkbox</returns>
 public string Checkbox(string name, string id, bool value, string cssclass, string label, string labelCssClass, int tabIndex)
 {
     var chkname = name + "_chk";
     var chkid = id + "_chk";
     var chk = new TagBuilder("input").Name(chkname).ID(chkid).type("checkbox");
     var hdn = new TagBuilder("input").Name(name).ID(id).type("hidden");
     // Figure out the value
     if (value)
     {
         chk.@checked(true);
         hdn.value("true");
     }
     else
     {
         chk.@checked(false);
         hdn.value("false");
     }
     // Add the label
     if (string.IsNullOrEmpty(label) == false)
     {
         if (!string.IsNullOrEmpty(labelCssClass))
             chk.Label(label, labelCssClass);
         else
             chk.Label(label);
     }
     // Add the class if asked
     if (string.IsNullOrEmpty(cssclass) == false)
     {
         chk.AddClass(cssclass);
     }
     if (tabIndex != 0)
     {
         chk.tabIndex(tabIndex);
     }
     // Wireup events
     chk.onclick("jQuery('#" + id + "').val(this.checked);");
     // Return the value
     return chk.ToString() + hdn;
 }
예제 #2
0
        /// <summary>
        /// Generates the label string (only when specified) to use for the element
        /// </summary>
        /// <returns></returns>
        private string GetLabelString()
        {
            if (string.IsNullOrEmpty(_label)) return "";

            var lbl = new TagBuilder("label");
            if (string.IsNullOrEmpty(GetAttribute("id")) == false)
            {
                lbl.@for(GetAttribute("id"));
            }
            lbl.AddClass(string.IsNullOrEmpty(_labelclass) == false ? _labelclass : "fieldlabel");
            if (string.IsNullOrEmpty(_labelWidth) == false)
            {
                lbl.width(_labelWidth);
            }
            if (_labelIsHtml)
            {
                lbl.InnerText(_label);
            }
            else
            {
                lbl.InnerHtml(_label);
            }
            return "\r\n" + lbl + "\r\n";
        }