my code is to handle the maxlength in the multiline textbox (textarea) so it works just like maxlength in the singleline text box , so I handled it onkeypress , but if I copy and paste , i want to substring the length to the maxlength from the clipboard , just to behave like the singleline textbox, the problem that the clipboard works only for the internet explorer but it doesn't work in other browsers
so function in JScript.js
function count(Obj, long) {
//IE only
var board = new String();
var maxlength = new Number(parseInt(long ));
if (window.event.ctrlKey) {
if (window.clipboardData != "") {
if (window.clipboardData.getData("Text").length >= maxlength) {
board.value = window.clipboardData.getData("Text");
Obj.value = board.value.substring(0, maxlength);
}
}
}
if (Obj.value.length >= maxlength) {
return false;
}
else
return true;
}
and wrote in vb.net :
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
If (Me.textbox1.MaxLength <> 0) Then
Me.textbox1.Attributes.Add("onpaste", "return count (this,'" + Me.textbox1.MaxLength.ToString + "');")
Me.textbox1.Attributes.Add("onkeypress", "return count (this,'" + Me.textbox1.MaxLength.ToString + "');")
End If
End Sub
and in aspx i wrote :
<head runat="server">
<title>Untitled Page</title>
<script src="JScript.js" language="jscript" type ="text/jscript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="textbox1" runat ="server" Textmode="MultiLine" MaxLength="10"></asp:TextBox>
</div>
</form>
</body>
</html>
so, It works very proper in Internet explorer , but in chrome ,it limits to the maximum length in writing but in copy and paste it doesn't work, as clipboard is not working in chrome, is there any way to make it work in multi-Browser?
p.s :the above is just a sample
Thanks and Best regards,
Sandy