Reputation: 4179
I have a TextBox
control and want to be able to copy content of TextBox
.
Properties of TextBox
look like this;
textBox1.Enabled = false;
textBox1.ReadOnly = false;
I cannot copy content of textBox1 even though ReadOnly property is false.
Is there any suggestion?
Upvotes: 8
Views: 15470
Reputation: 739
<input type="text" id="txtMobileNo" runat="server" onkeypress="return onlyNos(event,this);" class="form-control input-sm m-bot15" readonly="readonly" maxlength="10" style="font-weight: bold; background-color: #ecf9ec" tabindex="0" />
use readonly="readonly" in textbox code
Upvotes: 1
Reputation: 1358
textBox1.ReadOnly = true;
you can even use a copy button and code as follows:
System.Windows.Forms.Clipboard.SetText(textBox1.Text);
Upvotes: 4
Reputation: 172398
Ýou may try this if you want the user to allow copy paste:
textBox1.ReadOnly = true;
From MSDN forum
In the context of a TextBox, readonly allows the user to set focus to and select and copy the text but not modify it. A disabled TextBox does not allow any interaction whatsoever.
Use ReadOnly when you have data that you want the user to see and copy, but not modify. Use a disabled textbox, when the data you are displaying is not applicable in for the current state of a dialog or window.
Upvotes: 13
Reputation: 4697
You should set your textboxes to ReadOnly = true
instead of Enabled = false
if you want to support copy/paste.
Upvotes: 5