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,
Niradhip ChakrabortyPosted Dec 6, 2008, 6:15 PM
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.
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;
}
}
Now call this function in onblur from pagebehind.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txt_Final_Sale_Enter.Attributes.Add("OnBlur", "return validate()");
}
}
George LaingPosted Dec 5, 2008, 9:11 PM
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
Niradhip ChakrabortyPosted Dec 5, 2008, 7:43 PM
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");