remove spaces in search criteria

2 posts, 0 answers
  1. Robin
    Robin avatar
    23 posts
    Member since:
    Oct 2011

    Posted 23 Jan 2012 Link to this post

    I needed to be able to trim leading & trailing spaces that may have been inadvertently entered by the user as part of their search criteria. I tried to find documentation on this to no avail. If there's a better way to do it, please let me know. 

    Until then, this is what I did...
    I used a separate button to execute the search. The onclick of that button fires this method:

       protected void FilterData(object sender, EventArgs e)

    And LoopThruFilterControls looks like this:
        private void LoopThruFilterControls(ControlCollection cc)
            for (int i = 0; i < cc.Count; i++)
    string controlType = cc[i].GetType().Name;
    if(controlType.Equals("TextBox", StringComparison.CurrentCultureIgnoreCase))
    TextBox tmp = (TextBox)cc[i];
                    ((TextBox)cc[i]).Text = tmp.Text.Trim();
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Jan 2012 Link to this post


    I have tried the following code after accessing the TextBox and it worked as expected.
     string t= textbox.Text;
     string s = t.Trim();
     text.Text = s;

    Hope it helps.

Back to Top