Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want crate calculation form i have 3 textbox
1- Quantity
2- Rate
3- Total Amount (this textbox is readonly)
Total Amount = (Quentity * Rate) but after calculation i can change TotalAmount value using browser inspect element.
So I want user can't change textbox value, i am using MVC Razor.
Posted
Updated 20-Mar-20 2:11am
v2
Comments
aarif moh shaikh 23-Sep-15 6:31am    
you can disable right click of browsers
ZurdoDev 20-Mar-20 8:22am    
That won't help. User can still click F12 or use other browsers.

You can't stop people using dev tools etc, the solution to your problem is to use html and http properly. If you want the total amount field to be one you control and not the user, then that's what you do. Show it as a label or text rather than a textbox. In your form actions when you want the total amount you calculate it from the amount * quantity.
 
Share this answer
 
v2
Comments
Ravi Kant Rajput--From-Kanpur 23-Sep-15 8:26am    
Thanks for response

But i want calculate value on textbox change event and on submit button click we want store in database
F-ES Sitecore 23-Sep-15 8:30am    
You can re-calculate on the change events of the textbox if you want, but update the html of the label rather than the value of a textbox. The value you actually use should be calculated from the quantity and amount, and you shouldn't represent the amount as a textbox either. You should be submitting a quantity (textbox), a product ID (or whatever it is you're adding) and in your action you get the amount from the ID and multiply that by the given quantity and that is your total. Never trust data that comes from the client....that is how you secure your site. Not by disabling F12 or right-clicks or by adding reams of javascript that hackers will disable anyway.
Richard Deeming 23-Sep-15 9:08am    
+50 for that! :)
Hi,

You can disable right click and the F12 button to prevent the issue.
Follow the below links.

1.) Disable right click
2.) Disable F12 button

Thanks,
Sisir Patro
 
Share this answer
 
Comments
Ravi Kant Rajput--From-Kanpur 23-Sep-15 7:53am    
Hi,

In Asp.net we do not face this type of problem but currently i switch in mvc razor we face lot of security problem in mvc . please suggest me i want create simple calculation form using razor.
[no name] 23-Sep-15 7:59am    
I am not sure about the razor. If you will handle this using the javascript or jquery I believe it will work for all.
Ravi Kant Rajput--From-Kanpur 23-Sep-15 8:02am    
Thank You Sir
[no name] 23-Sep-15 8:04am    
You are welcome dear... :)
Richard Deeming 23-Sep-15 9:07am    
Disabling the context menu and the F12 key will not stop anyone from using the developer tools!

Firstly, there are other key combinations to bring up the tools. For example, in Firefox, Ctrl+Shift+K

Secondly, even if you manage to disable every key combination, you can still use the menu to bring up the developer tools. Javascript code is not able to interfere with the browser's menu, as that would be a major security risk.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900