We help IT Professionals succeed at work.

Using RTrim with a textbox for trailing spaces

dylanone
dylanone asked
on
612 Views
Last Modified: 2008-02-01
I have the following piece of code in a .aspx file - can someone tell me - how I can do a RTrim on the data that get's entered this field.

<asp:textbox id="FirstName" title="First Name Label" runat="server" />

I have users sometimes typing in trailing spaces and it's causing problems. I assume by using an RTrim if someone types in a first name that is two words say Mary Ann that the RTrim will take off any trailing spaces?

Thanks



Comment
Watch Question

Top Expert 2004
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Well - I looked at what you wrote and the URL and I placed the code in the OnClick method and tried it in the onPageLoad and no matter what I do - it doesn't recognize the code.

I'll look at it tomorrow with a fresh set of eyes.

Thanks

Top Expert 2004

Commented:
to "recognize the code" ?

Author

Commented:
Example I have placed the following three Trim Ends into the method that get's called when I click the serach button and if I add spaces at the end - the TrimEnd(Null) doesn't fire - it ignores these lines of code.

private void btnSearch_Click(object sender, System.EventArgs e)
            {                  
                        
                  wc.ICriteriaField criteriaField = (wc.ICriteriaField) this.FindControl("searchCriteria");
                  
                  string fname = FirstName.Text.TrimEnd(null);
                  string lname = LastName.Text.TrimEnd(null);
                  string keyw = Keyword.Text.TrimEnd(null);
                  string query = criteriaField.Value;
                              

                  cWeb.UrlContext url = cWeb.UrlContext.CurrentClone;
                  url.Page = "Display.aspx";
                  url.Query = query;

                  this.Context.Response.Redirect(url.ToString(), true);
            }

Author

Commented:
OK so I tried to get this to work again and I've made some progress:

I tried to use the MS example and create an array of items I want to trim - then I tried passing that into my query string - but still it doesn't trim the spaces.

Now what's interesting is that the aspx page is formulated as such

<asp:TextBox id="txtFirstName" runat="server" CriteriaField="FirstName" width="204px"></asp:TextBox>

and it doesn't utilize a name field instead it uses a CriteriaField which get's passed into the ICriteriaField to formulate a query control - this could be why my line before:
string fname = FirstName.Text.TrimEnd(null);
didn't find anything - so is their some special set-up I need when pulling from a control?

private void btnSearch_Click(object sender, System.EventArgs e)
            {                  
                                    
                  wc.ICriteriaField criteriaField = (wc.ICriteriaField) this.FindControl("attorneyCriteria");
                                    
                  char[] charsToTrim = {' '};
                  
                  string query = criteriaField.Value.TrimEnd(charsToTrim);
                                          
                  
                  cWeb.UrlContext url = cWeb.UrlContext.CurrentClone;
                  url.Page = "List.aspx";
                  url.Query = query;
                                    
                  this.Context.Response.Redirect(url.ToString(), true);
            }

Author

Commented:
I don't have this 100% working yet - but at least - I'm now on the right track!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.