Skip to content

Text Box Methid

George Laing

Asked Dec 5, 2008, 1:43 PM EST3 answers
Share
LinkedInX

Hi ,
   I have a screen with a text box, . I want to be able to edit a number to show as currency before the screen is loaded and when someone enters a number I want it to show as currency. I cannot figure out which method I would use to put my code in. The text box is txt_Final_Sale. I tried
 txt_Final_Sale_Enter((object sender, EventArgs e)
{
}

But it did not activate. Can anyone tell me which property or method I need to use to execute code for the text box?

Thanks,

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Niradhip Chakraborty
    +1

    I am using a data reader to read the value from database,which is a numeric and
    I am converting it to currency in following way.

    txtCashAmount.Text = Convert.ToDouble(sdrData["cus_cur_MaximumCashAmount"]).ToString("C");

    +1
  • +1

    Hi,

      Thanks, I have that part working.. But when the user types a new amount in the box I want to have it show back to them as an amount. I also want to have code that will validate the box. I just do not know which method to use?

    Thanks

    +1
  • Niradhip Chakraborty
    +1

    you can use the following javascript function;

    use this java script function in your aspx page and call it in onblur from your page behind.

    <script language="javascript" type="text/javascript">

    JavaScript
    function validate()
    {
     if(document.getElementById("txt_Final_Sale_Enter").value=="")
              {
                 alert("Please Enter The Amount");
                 document.getElementById("txt_Final_Sale_Enter").focus();
                 return false;
              }
             else
             {
               document.getElementById("txt_Final_Sale_Enter").value = '$' + document.getElementById("txt_Final_Sale_Enter").value;
             }
    }


    </script>

    Now call this function in onblur from pagebehind.

    C#
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
         txt_Final_Sale_Enter.Attributes.Add("OnBlur", "return validate()");
      }
    }
    +1