示例#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>
 /// Create an image tag sorrounded by an anchor tag with a rollover effect.
 /// </summary>
 /// <param name="src">The source of the image to use as the default state</param>
 /// <param name="hoversrc">The source of the image to use as the hover state</param>
 /// <param name="url">The url to assign to the anchor tag</param>
 /// <param name="alt">Assign this alt text to the image</param>
 /// <param name="newWindow">Determine whether to open the link in a new window</param>
 /// <returns>A TagBuilder class to continue to create the tag by adding attr classes etc.</returns>
 public string ImageLinkHover(string src, string hoversrc, string url, string alt, bool newWindow)
 {
     var tb = new TagBuilder("a").href(url).inlineblock().InnerHtml(ImageHover(src, hoversrc).Alt(alt).ToString());
     if (newWindow)
         tb.Target_Blank();
     return tb.ToString();
 }