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 ChakrabortyRank #428 · 5.8K pointsPosted Dec 5, 2008, 2:43 PM EST
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");
George Laing37 pointsPosted Dec 5, 2008, 4:11 PM EST
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 ChakrabortyRank #428 · 5.8K pointsPosted Dec 6, 2008, 1:15 PM EST
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">
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.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { txt_Final_Sale_Enter.Attributes.Add("OnBlur", "return validate()"); } }