readonly

html input readonly 和 disable的区别

感情迁移 提交于 2019-12-04 09:46:36
Readonly和Disabled它们都能够做到使用户不能够更改表单域中的内容。但是它们之间有着微小的差别,总结如下: Readonly只针对input(text / password)和textarea有效,而disabled对于所有的表单元素都有效,但是表单元素在使用了disabled后,当我们将表单以POST或GET的方式提交的话,这个元素的值不会被传递出去,而readonly会将该值传递出去( readonly接受值更改可以回传,disable接受改但不回传数据 )。 一般比较常用的情况是: 1. 在某个表单中为用户预填了某个唯一识别代码,不允许用户改动, 但是在提交时需要传递该值,此时应该将它的属性设置为readonly 。 2. 经常遇到当用户正式提交了表单后需要等待管理员的信息验证,这就不允许用户再更改表单中的数据,而是只能够查看,由于disabled的作用元素范围大,所以此时应该使用disabled,但同时应该注意的是要将submit button也disabled掉,否则只要用户按了这个按钮,如果在数据库操作页面中没有做完整性检测的话,数据库中的值就会被清除。如果说在这种情况下用readonly来代替disabled的话,若表单中只有input(text / password)和textarea元素,那还是可以的,如果存在其他发元素,比如select

C# return a variable as read only from get; set;

徘徊边缘 提交于 2019-12-04 08:15:02
问题 I swear I have seen an example of this but have been googling for a bit and can not find it. I have a class that has a reference to an object and need to have a GET; method for it. My problem is that I do not want anyone to be able to fiddle with it, i.e. I want them to get a read only version of it, (note I need to be able to alter it from within my class). Thanks 回答1: No, there's no way of doing this. For instance, if you return a List<string> (and it's not immutable) then callers will be

Programmatically Changing ReadOnly Mode on DataGridView Rows

别说谁变了你拦得住时间么 提交于 2019-12-04 05:51:38
Without explaining the entire context, my problem is basically this: I have a datagridview on a Windows Form which is bound to an Entity Framework DbSet: dbSet<TEntity>.Local.ToBindingList() . If I set the datagridview's ReadOnly property to true (in design view), and then have this statement in my code: myDataGridView.Rows[rowIndex].ReadOnly = false; It steps right through without changing the value! (And no, my datasource is not readonly.) Looping through the cells in the row and setting each cell's ReadOnly property individually doesn't work either: foreach (DataGridViewCell cell in

Overriding ReadOnly Property in a subclass to make it Read/Write (VB.NET or C#)

一个人想着一个人 提交于 2019-12-04 05:18:16
This doesn't seem possible in VB.NET with properties since the property statement itself must describe whether it is ReadOnly or not. In my example below, it doesn't let me make the ReadWriteChild compile. I guess I could make the parent Read/Write, and then have the ReadOnlyChild's setter not do anything, but that seems sort of hacky. The best alternative seems to be abandoning properties in favor of getter/setter methods in this case. Public MustInherit Class Parent Public MustOverride ReadOnly Property Foo() As String End Class Public Class ReadOnlyChild Inherits Parent Public Overrides

Why readonly and volatile modifiers are mutually exclusive?

元气小坏坏 提交于 2019-12-04 03:01:42
I have a reference-type variable that is readonly , because the reference never change, only its properties. When I tried to add the volatile modifier to it the compiled warned me that it wouldn't let both modifiers apply to the same variable. But I think I need it to be volatile because I don't want to have caching problems when reading its properties. Am I missing anything? Or is the compiler wrong? Update As Martin stated in one of the comments below: Both readonly and volatile modifiers apply only to the reference, and not to the object's properties, in the case of reference-type objects.

Why can't I initialize readonly variables in a initializer?

谁说我不能喝 提交于 2019-12-04 02:47:07
问题 Why can't I initialize readonly variables in a initializer? The following doesn't work as it should: class Foo { public readonly int bar; } new Foo { bar=0; }; // does not work Is this due to some technical limits of the CLR? EDIT I know that new Foo { bar=0; } is the same as new Foo().bar=0; , but is "readonly" enforced by the CLR, or is it just a compiler limitation? 回答1: Allowing a readonly to be set in an initializer introduces contradictions and complications that can't be enforced at

readonly class design when a non-readonly class is already in place

非 Y 不嫁゛ 提交于 2019-12-04 01:51:03
I have a class that upon construction, loads it's info from a database. The info is all modifiable, and then the developer can call Save() on it to make it Save that information back to the database. I am also creating a class that will load from the database, but won't allow any updates to it. (a read only version.) My question is, should I make a separate class and inherit, or should I just update the existing object to take a readonly parameter in the constructor, or should I make a separate class entirely? The existing class is already used in many places in the code. Thanks. Update:

How to make a QLineEdit not editable in Windows

元气小坏坏 提交于 2019-12-03 16:17:02
问题 I'm using Qt 5.2 and I would like to make a QLineEdit not editable. The problem with this is, that it doesn't appear like it. When using setReadOnly(true) it stays with white background and looks like it is still editable. If I disable it, then it turns gray and the text also gets a lighter gray. The problem is, that one can not copy the text from it, in a disabled state. So how can I make a QLineEdit properly non-editable and also make it look like it. In Windows such a control is usually

Android: How to make a NFC Tag Ready only for users and writable for me?

混江龙づ霸主 提交于 2019-12-03 15:33:02
I have an app that design personalized tags that, when it is detected by an android phone, launches another app with some content. It all works fine and I know how to make a read only nfc Tag. The problem is, I would like to make a NFC Tag only readable by users of the other app. But I also want , if necessary, modify these tags in order to be rewritten. But I want to prevent from users to do themselves. that's why a ndef.makeReadOnly() is not appropriate for me.. does anyone can help me ??? It depends somewhat on the exact tags you will be using. The standard NFC Forum tag types for storing

Static string literal table?

风流意气都作罢 提交于 2019-12-03 12:00:19
What is the correct way in C++ to create a global & static table of strings? By "global", I mean: Useable from any file that includes the header. But not part of some run-time created singelton objcet. By "static", I mean: As little run time set up possable. Data in read only memory pages. Only 1 instance of data per app. By "string", I mean: Null terminated array of chars is fine. std::string would be nice, but I don't think it can be done in terms of the above. Correct? By "table", I mean: I mean an indexable array. So I guess not a table per-se. But I'm flexable on this point. Open to ideas