Revision: 21639
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 16, 2009 23:49 by mpcircuitry
Initial Code
using System; using System.Data; using System.Configuration; using System.Collections.Generic; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; /// <summary> /// Summary description for HTML /// </summary> public class HTML { public HTML() { // // TODO: Add constructor logic here // } public static string link(string url, string title, string cssClass, string javascript) { HTML mHt = new HTML(); return "<a href=\"" + url + "\"" + mHt.getCssClass(cssClass) + mHt.getJavascript(javascript) + " >" + title + "</a>\n"; } public static string link(string url, string title, string cssClass) { return HTML.link(url, title, cssClass, ""); } public static string link(string url, string title) { return HTML.link(url, title, "", ""); } public static string input(string id, string value, int maxLength , string cssClass, string javascript) { HTML mHt = new HTML(); string strMaxLength = ""; if (maxLength != -1) { strMaxLength = "size=\"" + maxLength.ToString() + "\" maxlength=\"" + maxLength.ToString() +"\""; } return "<input type=\"text\" id=\"" + id + "\" name=\"" + id + "\" " + strMaxLength + "value=\"" + value + "\" " + mHt.getCssClass(cssClass) + mHt.getJavascript(javascript) + "/>\n"; } public static string input(string id, string value, int maxLength, string cssClass) { return HTML.input(id, value, maxLength, cssClass, ""); } public static string input(string id, string value, int maxLength) { return HTML.input(id, value, maxLength, "", ""); } public static string submit(string id, string value, string cssClass, string javascript) { HTML mHt = new HTML(); return "<input type=\"submit\" id=\"" + id + "\" name=\"" + id + "\" value=\"" + value + "\" " + mHt.getCssClass(cssClass) + mHt.getJavascript(javascript) + "/>\n"; } public static string submit(string id, string value, string cssClass) { return HTML.submit(id, value, cssClass, ""); } public static string submit(string id, string value) { return HTML.submit(id, value, "", ""); } public static string drop(string id, string[,] data, string selectedValue, string cssClass, string javascript) { HTML mHt = new HTML(); if (data != null) { data[0, 0] = ""; if (data.GetUpperBound(1) > 0) { data[0, 1] = ""; } } string dropString = "<select name=\"" + id + "\" id=\"" + id + "\" " + mHt.getCssClass(cssClass) + " " + mHt.getJavascript(javascript) + " >\n"; for (int i = 0; i < data.GetUpperBound(0) + 1 && data.GetUpperBound(1) == 1; ++i) { String curDesc = data[i, 1].ToString().Replace(" ", " "); string selected = selectedValue == data[i, 0].ToString() ? " selected=selected " : ""; while (curDesc.IndexOf(" ") > -1) { curDesc = curDesc.Replace(" ", " "); } dropString += "<option value=\"" + data[i, 0].ToString() + "\" " + selected + ">" + curDesc + "</option>\n"; } dropString += "</select>\n"; return dropString; } public static string drop(string id, string[,] data, string selectedValue, string cssClass) { return HTML.drop(id, data, selectedValue, cssClass, ""); } public static string drop(string id, string[,] data, string selectedValue) { return HTML.drop(id, data, selectedValue, "", ""); } public static string image(string src, string alt, string css, string javascript) { HTML mHt = new HTML(); return "<img src=\"" +src + "\" alt=\"" + alt + "\" " + mHt.getCssClass(css) + " " + mHt.getJavascript(javascript) + ">\n"; } public static string list(string id, string[,] data, string cssClass, string javascript) { if (data != null) { data[0, 0] = ""; //data[0, 1] = ""; } HTML mHt = new HTML(); string dropString = "<select name=\"" + id + "\" id=\"" + id + "\" " + mHt.getCssClass(cssClass) + " " + mHt.getJavascript(javascript) + " size=\"5\">\n"; if (data != null) { for (int i = 1; i < data.GetUpperBound(0) + 1; ++i) { String curDesc = data[i, 0].ToString().Replace(" ", " "); while (curDesc.IndexOf(" ") > -1) { curDesc = curDesc.Replace(" ", " "); } dropString += "<option value=\"" + data[i, 0].ToString() + "\">" + curDesc + "</option>\n"; } } dropString += "</select>\n"; return dropString; } public static string button(string id, string value, string cssClass, string javascript) { HTML mHt = new HTML(); return "<input type=\"button\" id=\"" + id + "\" name=\"" + id + "\" value=\"" + value + "\" " + mHt.getCssClass(cssClass) + mHt.getJavascript(javascript) + "/>\n"; } public string getCssClass(string cssClass) { string modCssClass = ""; if (cssClass != "") { modCssClass = " class=\"" + cssClass + "\""; } return modCssClass; } public string getJavascript(string javascript) { string modJavascript = ""; if (javascript != "") { modJavascript = " " + javascript; } return modJavascript; } public static string hidden(string id, string value, string cssClass, string javascript) { HTML mHt = new HTML(); return "<input type=\"hidden\" id=\"" + id + "\" name=\"" + id + "\" value=\"" + value + "\" " + mHt.getCssClass(cssClass) + mHt.getJavascript(javascript) + "/>\n"; } public class cTable { public cTableRows Rows = new cTableRows(); private string tableBorder = ""; public void border(bool on) { if (on == true) { this.tableBorder = " border=\"1\" "; } else { this.tableBorder = ""; } } public string Text() { return "<table " + this.tableBorder + ">" + Rows.text() + "</table>"; } } public class cTableRows { private Dictionary<string, string> myRows = new Dictionary<string, string>(); string rows = ""; public void Add(cTableRow value) { myRows.Add(myRows.Count.ToString(), value.text()); //"<td>" + value + "</td>\n"; rows += "<tr>" + value.text() + "</tr>\n"; } public string text() { return rows; } } public class cTableRow { public cRowCells Cells = new cRowCells(); public string text() { return Cells.text(); } } public class cRowCells { private Dictionary<string, string> myCells = new Dictionary<string, string>(); private string cells = ""; public void Add(cTableCell value) { myCells.Add(myCells.Count.ToString(), value.Text); cells += "<td " + value.getSpan() + value.getRowSpan() + ">" + value.Text + "</td>\n"; } public string text() { return cells; } } public class cTableCell { public string Text; public void rowSpan(int num) { cellRowSpan = " rowspan=\"" + num.ToString() + "\""; } public void Span(int num) { cellSpan = " colspan=\"" + num.ToString() + "\" "; } public string getSpan() { return cellSpan; } public string getRowSpan() { return cellRowSpan; } private string cellSpan = ""; private string cellRowSpan = ""; } }
Initial URL
Initial Description
This class uses static methods to create html controls on the fly in .NET
Initial Title
HTML Class for C#
Initial Tags
html, c, Net
Initial Language
C#