txtbox data type

Results 1 to 3 of 3

Thread: txtbox data type

  1. #1
    Join Date
    Dec 1969

    Default txtbox data type

    I have a txtbox (called "estimated savings" - a monetary value)on an aspform that needs to write a value to a SQl db.I don't want people to be able to enter a comma or any alphabet letters into the txt, only a . (point) as the decimal value and only numeric values from 0 t0 9, eg 126.89 When I make the txtbox (client) a numeric field it still allows the comma, but takes it out when writing to the db, for ex 23,78 is written as 2378. What should I make the data type(I've tried decimal and integer)and how do I validate that there is not a comma or letters in the typed textbox before writing to the db ???? Thanks, your help will be much appreciated !

  2. #2
    Join Date
    Dec 1969

    Default RE: txtbox data type

    you might want to validate client-side, while the user is typing and give an error any time he types a ','?

  3. #3
    Join Date
    Dec 1969

    Default Use a validation control

    Use one of the many rich validation controls ASP.NET provides you. Check out:<BR><BR>Form Validation with ASP.NET - It Doesn&#039;t Get Any Easier!<BR>http://www.4guysfromrolla.com/webtech/090200-1.shtml<BR><BR>Specifically, I&#039;d recommend using RegularExpressionValidator control if you must make certain there&#039;s no comma. Something like:<BR><BR><BR>&#060;form runat="server"&#062;<BR><BR>Enter Estimated Savings:<BR>$&#060;asp:textbox id="txtSavings" runat="server" /&#062;<BR>&#060;asp:RegularExpressionValidator runat="server"<BR> id="regexpSavings"<BR> ControlToValidate="txtSavings"<BR> ValidationExpression="(d+)&#124(d+.dd)"<BR> ErrorMessage="Please enter a numeric value without any commas."<BR> Display="Dynamic" /&#062;<BR>&#060;p&#062;&#060;asp:button runat="server" text="Submit Form" /&#062;<BR>&#060;/form&#062;<BR><BR><BR>(You may also want to use a RequiredFieldValidator on the txtSavings control if the value must be entered.)<BR><BR>Anyway, in the Page_Load event handler you can then access the data like so (this is in the same ASP.NET page as the code above):<BR><BR>&#060;script language="VB" runat="server"&#062;<BR> Sub Page_Load(source as Object, e as EventArgs)<BR> If Page.IsPostBack then<BR> &#039;Did the user enter valid data?<BR> If Page.IsValid then<BR> Response.Write(txtSavings.Text & " is valid!")<BR> Else<BR> Response.Write(txtSavings.Text & " is NOT valid!")<BR> End If<BR> End If<BR> End Sub<BR>&#060;/script&#062;<BR><BR>Hope this helps! For more info on ASP.NET be sure to check out the articles in the 4Guys ASP.NET Article Index!<BR>http://www.4guysfromrolla.com/webtech/LearnMore/ASPPlus.asp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts