8 Replies - 800 Views - Last Post: 19 January 2012 - 12:54 PM Rate Topic: -----

Topic Sponsor:

#1 drilli  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 105
  • Joined: 26-May 09

Using validator server controls to validate some textbox controls

Posted 03 October 2011 - 11:35 AM

Hi all.I have some text boxes in my aspx page and some text boxes will axxpet only string values and some other will accpet only integers or double values.

Is there any validation control to validate a textbox such that it will accpt only integeres or only string values?

How can I do this?

Thank You for reading this topic.
Is This A Good Question/Topic? 0
  • +

Replies To: Using validator server controls to validate some textbox controls

#2 Nakor  Icon User is offline

  • ASP.NET/C# Developer
  • member icon

Reputation: 346
  • View blog
  • Posts: 1,228
  • Joined: 28-April 09

Re: Using validator server controls to validate some textbox controls

Posted 04 October 2011 - 04:10 AM

I don't know of a validator but if you use the AjaxControlToolkit there is a FilteredTextBoxExtender control that allows you to limit the input to specific values

FilteredTextBoxExtender

This post has been edited by Nakor: 04 October 2011 - 04:11 AM

Was This Post Helpful? 0
  • +
  • -

#3 drilli  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 105
  • Joined: 26-May 09

Re: Using validator server controls to validate some textbox controls

Posted 04 October 2011 - 07:39 AM

Thank You for your answer...but as i was reading in some forums about thit i found that in RegularExpressionValidator in the validationExpression propertie I can put this : "^[A-Za-z]{1,}$" than it will prevent user to put number in that field .It also prevent users to put spaces(it useful for fields in wich user will write for example name or surname or something like that).

I will llok how to use ajax toolkit because I`m not using it yet..but if you have anything useful for me to learn how to use Ajax Toolkit it will be good for me to learn also about that.

Thank You and have a nice day!
Was This Post Helpful? 0
  • +
  • -

#4 drilli  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 105
  • Joined: 26-May 09

Re: Using validator server controls to validate some textbox controls

Posted 04 October 2011 - 08:41 AM

View PostNakor, on 04 October 2011 - 05:10 AM, said:

I don't know of a validator but if you use the AjaxControlToolkit there is a FilteredTextBoxExtender control that allows you to limit the input to specific values

FilteredTextBoxExtender



Thank You very much...I just start using Ajax toolkit and i also used FilterTextBox and it is very good.It prevents users to write numbers or uppercaseletters or lowercaseletters or combine of those properties.

Thanks it is very good for my web appliation.
Was This Post Helpful? 0
  • +
  • -

#5 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 202
  • View blog
  • Posts: 775
  • Joined: 03-June 10

Re: Using validator server controls to validate some textbox controls

Posted 04 October 2011 - 11:54 AM

Hmm I wouldn't have suggested an Ajax extender when there are tons of Validating ASP.NET Server Controls available right in the .NET Framework.

-Frinny
Was This Post Helpful? 0
  • +
  • -

#6 drilli  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 105
  • Joined: 26-May 09

Re: Using validator server controls to validate some textbox controls

Posted 04 October 2011 - 12:46 PM

well I have another question about validators.I am a starter in ASP.NET and in programming in general and this is my firts time working with validators.As I can see all validations happens in client side and if there is any error the page is not doing a postback...so is ti nessesary to make validation also in server side .I mean do I Have to write code in code behind in server side?
Was This Post Helpful? 0
  • +
  • -

#7 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 202
  • View blog
  • Posts: 775
  • Joined: 03-June 10

Re: Using validator server controls to validate some textbox controls

Posted 04 October 2011 - 01:29 PM

You should always do server-side validation.


The validators use Javascript to validate the data before sending it to the server. They let the user correct everything so that there are less round-trips involved.

If the user is able to get around the Javascript validation (which is quite easy to do) in an attempt purposefully submit invalid data, you can check the Page.IsValid property in your server side to prevent any data processing that should not be done if the data is invalid. This will prevent any undesired outcome.

For example:
Protected Sub Buttonclick(ByVal sender As Object,ByVal e As EventArgs)
    If (Page.IsValid) Then
        errorLabel.Text = "Page is valid."
    Else
        errorLabel.Text = "Page is not valid!!"
    End If
End Sub


Honestly I recommend that you implement and test any custom sever-side validation first and then add Javascript to the page to supplement the validation process....

This post has been edited by Frinavale: 04 October 2011 - 01:30 PM

Was This Post Helpful? 1
  • +
  • -

#8 Nakor  Icon User is offline

  • ASP.NET/C# Developer
  • member icon

Reputation: 346
  • View blog
  • Posts: 1,228
  • Joined: 28-April 09

Re: Using validator server controls to validate some textbox controls

Posted 04 October 2011 - 09:48 PM

I just went with the extender because the question didn't really involve validation but was about limiting user input. Of course you should always validate the input on the server to make sure the data is in the correct form.
Was This Post Helpful? 0
  • +
  • -

#9 R.Stan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-October 11

Re: Using validator server controls to validate some textbox controls

Posted 19 January 2012 - 12:54 PM

Thank you for the sensible critique on www.dreamincode.net . Me & my neighbor were just preparing to do some research about this. We got a grab a book from our local library but I think I learned more from this post. I am very glad to see such great information being shared freely out there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1