Javascript field editable only to admins
I have a field called ProductName that has a specific product name in it. When logged in any user can update the product name by clicking on the text and hitting save.
The code came from http://www.appelsiini.net/projects/jeditable for this to be possible.
I have roles set up in ASP.net VB for admins and non-admins and was wondering if there is any way in the Javascript to state that only admins are allowed to edit that field.
This is the Javascript code for the editable field:
$('.productName.edit').editable(function (value, settings) {
var ProductID = $('input#body_ProductID').val();
var result = SubmitProductName(ProductID, value);
ret开发者_JAVA技巧urn (value);
}, {
width: '350',
submit: 'Save Changes',
cancel: 'Cancel',
onBlur: 'ignore'
});
Here is the field itself in ASP:
<asp:FormView ID="fvProduct" runat="server" DataSourceID="dsProduct">
<ItemTemplate>
<h1 class="productName edit"><%# Eval("ProductName")%></h1>
</ItemTemplate>
</asp:FormView>
I would really appreciate any help. Thanks.
You could do this in javascript, but this will be bypass-able for anyone disabling/hacking javascript (which is very easily doable). You should do this on server-side.
If you really want to do this in javascript, just check permission through an ajax call.
You should do this on server side but still if you want to do this on client side then when a user logs in you can store a cookie that keeps track of whether he is an admin or non-admin.Now when someone tries to edit the field check whether that cookie you stored says he is an admin or not. If he is admin then allow editing otherwise not.
精彩评论