Geeks With Blogs

News My Blog has been MOVED to
Michael Freidgeim's OLD Blog My Blog has been MOVED to

Previously I've posted a few Helper Classes . This post describes my HtmlHelper class:

      using System;
      using System.Text;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      /// Summary description for HtmlHelper.
      public class HtmlHelper
            // Methods
            public HtmlHelper()
            public static void AddBookMark(Control parent, string bookMarkName)
                  LiteralControl control1 = new LiteralControl();
                  control1.Text = "<a name=\"" + bookMarkName + "\">";
            //    'idea from
            //    'MNF seems that I can't use bookmark this way.BookMark appends to url and seems lost viewstate
            //    'Didn't find workaround so far -see for research
            public static void GoToBookMark(Page page, string bookMarkName)
                  StringBuilder sb = new StringBuilder();
                  sb.Append("<script language=\"JavaScript\">");
                  sb.Append("location.href=\"#" + bookMarkName + "\";");
                  page.ClientScript.RegisterClientScriptBlock(TypeForClientScript(),"GoToBookMark", sb.ToString());
            public static string ReplaceNewLine(string sMsg)
                  return sMsg.Replace(Environment.NewLine, NewLine);
            //    'set text and tooltip
            public static void SetClickToBtnText(Button btn, string text)
                  btn.ToolTip = "Click here to " + text;
                  btn.Text = text;
            public static string WriteLine(HttpResponse Response, string sMsg)
                  string text1= WriteLine( sMsg);
                  return text1;
            public static string WriteLine( string sMsg)
                  return sMsg + NewLine;
            /// Function replaces 2 or more spaces to one space.
            /// Function was created for use MetaBuilder ComboBox to modify list values.
            /// Client DHTML innerText replaces multiple spaces with one,
            /// but when return back to server string with single space doesn't match Listbox strings in ListItemCollection.FindByText Method
            public static string RemoveNonPreservedSpace(string strText)
                  Regex reNonPreservedText = new Regex(@"\s{2,}", RegexOptions.IgnoreCase);
                  // Do the replacements
                  strText = reNonPreservedText.Replace(strText, " ");
                  return strText;
            //from ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbwlkWalkthroughCreatingCustomWebControls.htm
            public static string WriteHyperLinkHtml(string Url,string Text)
                        StringWriter sw = new StringWriter();
                        HtmlTextWriter tw = new HtmlTextWriter(sw);
                        HyperLink placeholderLink = new HyperLink();
                        // put control text into the link's Text
                        placeholderLink.NavigateUrl = Url;
                        if ((Text==null) || (0==Text.Length)) Text=Url;
                        placeholderLink.Text = Text;
                        return sw.ToString();
        private static Type TypeForClientScript()
            return typeof(HtmlHelper);
            // Fields
            public const string NewLine = "<BR />";
Posted on Monday, October 8, 2007 1:01 AM | Back to top

Comments on this post: My HtmlHelper class

# re: My HtmlHelper class
Requesting Gravatar...
Humm... interesting,

I used it and It works absolutely fine

Thanks for bringing this up
Left by web development company on Aug 11, 2009 5:38 AM

Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: