I have and Issue where I have set a Textbox.ReadOnly = TRUE and it does stop you from typing into the field. But it also allows for you to Paste into it still. I saw that MS had fixed this type of issue in VS12, but have they reintroduce it back in? I
don't want to use the ShortCutsEnabled = FALSE as that effects the whole Page and not just the Field I am concerned with. I am in VS17 using VB. When I Right-Click and the Context Menu drops down, Cut and Paste are not listed as options, yet Ctrl-V will
effect the field.
Public Overrides Sub DisableControl()
TextControl.ReadOnly = True
TextControl.Attributes.Add("onpaste", "return false;")
End Sub
When you call the DisableControl method? According to your code, I create a sample using the following code, it seems that every thing works well.
The TextBox1 could use Ctrl+V, and the TextBox2 could not use it.
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox2.ReadOnly = True
TextBox2.Attributes.Add("onpaste", "return false;")
End Sub
I suggest you could use F12 develop tools to check the html element attribute and make sure the readonly and onpaste attributes are exist.
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
According to your code, I have created a sample and the screenshot as below:
As we can see that if we set the readonly attribute, we could not use Ctrl+V. I also test it on IE and Google browser, both of them could not use Ctrl+V.
So, I suggest you could try to use Ctrl+F5 to refresh the page and test it again. And you could also use F12 develop tools to check whether it contains some error.
Besides, you could also try to create a new page to test this part of code, and use different browser.
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I am beginning to think this is a Chrome issue. When looking in F12(Developer Mode) I don't see any errors, When I press F5 the fields that were blanked out are refilled back in with their values. When I save to exit the screen the data is unchanged,
Its almost like the "TextControl.ReadOnly = True" and "TextControl.Attributes.Add("onpaste", "return false;")" are being ignored.
With the way this is written: TextControl.Attributes.Add("onpaste", "return false;"), Do I need a function in JavaScript for onpaste? If I do where do I put it? I am guessing that the return false is answering the onpaste call directly.
Please check your code, it contains a spelling mistake. Please modify it as below:
onpause="return false;"
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Here we are in 2017 and this is still an issue one way or another across the board.
All I want is for the Browsers to behave correctly if you set a entry field to read only, it should be just that. I now have Chrome working, but Firefox is still acting the same. If a field is readonly why would you accept a paste to that field? I have
found threads going back close to 13 years for this type of issue. Why do I need a special Script for each browser for something it should all ready do, not change a field that is read only? Are their people that make fields readonly and then allow you to
paste into them?
None
0 Points
9 Posts
MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 15, 2017 01:20 PM|smiske|LINK
I have and Issue where I have set a Textbox.ReadOnly = TRUE and it does stop you from typing into the field. But it also allows for you to Paste into it still. I saw that MS had fixed this type of issue in VS12, but have they reintroduce it back in? I don't want to use the ShortCutsEnabled = FALSE as that effects the whole Page and not just the Field I am concerned with. I am in VS17 using VB. When I Right-Click and the Context Menu drops down, Cut and Paste are not listed as options, yet Ctrl-V will effect the field.
Star
9859 Points
2556 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 15, 2017 03:05 PM|AZMatt|LINK
See this thread...
https://forums.asp.net/t/1715648.aspx?make+Textbox+to+not+allow+to+copy+paste
Matt
None
0 Points
9 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 15, 2017 04:22 PM|smiske|LINK
This is what I have on the webpage yet it is still effected by Ctrl-V
<input name="__Update_RWMyField_13010_472_Int__Ctrl" type="text" value="103" readonly="readonly" id="__Update_RWMyField_13010_472_Int__Ctrl" placeholder="MyField" onpaste="return false;" class="form-control">
All-Star
50841 Points
9895 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 15, 2017 05:58 PM|A2H|LINK
You could try disabling copy paste using jquery
Change the textbox control id as per your design.
You can find a discussion on same topic here
Aje
My Blog | Dotnet Funda
None
0 Points
9 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 15, 2017 06:26 PM|smiske|LINK
From what I can tell tis will shut down the whole page for cut and paste, not just the ones that are .ReadOnly
All-Star
50841 Points
9895 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 15, 2017 07:07 PM|A2H|LINK
If you change the id to your textbox then it will disable copy paste for that textbox only
complete Code
Aje
My Blog | Dotnet Funda
All-Star
50841 Points
9895 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 15, 2017 07:11 PM|A2H|LINK
If you want to access only readonly textbox then you can use below code
Complete Code
Aje
My Blog | Dotnet Funda
None
0 Points
9 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 15, 2017 07:53 PM|smiske|LINK
I have never used jquery in conjunction with VB
Public Overrides Sub DisableControl()
TextControl.ReadOnly = True
TextControl.Attributes.Add("onpaste", "return false;")
End Sub
one thing that I think I have notice is that even if it is changed and you click save the field changed is not updated.
All-Star
45489 Points
7008 Posts
Microsoft
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 18, 2017 06:00 AM|Zhi Lv - MSFT|LINK
Hi smiske,
When you call the DisableControl method? According to your code, I create a sample using the following code, it seems that every thing works well.
The TextBox1 could use Ctrl+V, and the TextBox2 could not use it.
I suggest you could use F12 develop tools to check the html element attribute and make sure the readonly and onpaste attributes are exist.
Best regards,
Dillion
None
0 Points
9 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 18, 2017 01:47 PM|smiske|LINK
https://1drv.ms/i/s!ArH0evzxXv4aioQz99exPXzITaKN2w
this Is a link to the screen shot of the control.
All-Star
45489 Points
7008 Posts
Microsoft
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 19, 2017 05:26 AM|Zhi Lv - MSFT|LINK
Hi smiske,
According to your code, I have created a sample and the screenshot as below:
As we can see that if we set the readonly attribute, we could not use Ctrl+V. I also test it on IE and Google browser, both of them could not use Ctrl+V.
So, I suggest you could try to use Ctrl+F5 to refresh the page and test it again. And you could also use F12 develop tools to check whether it contains some error.
Besides, you could also try to create a new page to test this part of code, and use different browser.
Best regards,
Dillion
None
0 Points
9 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 19, 2017 02:44 PM|smiske|LINK
I am beginning to think this is a Chrome issue. When looking in F12(Developer Mode) I don't see any errors, When I press F5 the fields that were blanked out are refilled back in with their values. When I save to exit the screen the data is unchanged, Its almost like the "TextControl.ReadOnly = True" and "TextControl.Attributes.Add("onpaste", "return false;")" are being ignored.
With the way this is written: TextControl.Attributes.Add("onpaste", "return false;"), Do I need a function in JavaScript for onpaste? If I do where do I put it? I am guessing that the return false is answering the onpaste call directly.
None
0 Points
9 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 20, 2017 09:11 PM|smiske|LINK
I tried something different this time
It now works as expected, but I believe that the onPaste does nothing for me. and I will try to remove it.
the generated fields now look like this:
The readonly="readonly" does make me wonder what might be happening since the standard is suppose to be "readonly", making the "="readonly"" ignored.
All-Star
45489 Points
7008 Posts
Microsoft
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 21, 2017 02:53 AM|Zhi Lv - MSFT|LINK
Hi smiske,
Please check your code, it contains a spelling mistake. Please modify it as below:
onpause="return false;"
Best regards,
Dillion
None
0 Points
9 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 21, 2017 01:32 PM|smiske|LINK
This one seems to be out of left field? I am trying to stop Ctrl-V, Pasting into an element.
https://www.w3schools.com/jsref/event_onpaste.asp
I am not trying to Pause something
https://www.w3schools.com/jsref/event_onpause.asp
This is where onpaste was explained, but I must have missed something.
http://www.c-sharpcorner.com/blogs/disable-copypasteright-click-using-javascript-in-asp-net-textbox1
I did not find onpaste to work at all, so I removed it and checked for onkeydown="DontAllowPaste()"
SO I am considering this to be solved.
None
0 Points
9 Posts
Re: MS TextBox set to .ReadOnly = True allows Ctrl-V
Sep 25, 2017 05:37 PM|smiske|LINK
Here we are in 2017 and this is still an issue one way or another across the board.
All I want is for the Browsers to behave correctly if you set a entry field to read only, it should be just that. I now have Chrome working, but Firefox is still acting the same. If a field is readonly why would you accept a paste to that field? I have found threads going back close to 13 years for this type of issue. Why do I need a special Script for each browser for something it should all ready do, not change a field that is read only? Are their people that make fields readonly and then allow you to paste into them?