

<script language="javascript" type="text/javascript">
	 function EscapeKeys(evt) {
		 var evt = (evt) ? evt : ((event) ? event : null);
		 var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
		 var a = null;
		 if (node.getAttribute("AllowKeypress")) { a = node.attributes("AllowKeypress").value }

		 if ((evt.keyCode == 13) && (a !== "true")) { return false; }
	  }
	// comment out the line below if you need to conditionally enable/disable the function
		 document.onkeypress = EscapeKeys;
</script>


On any pages where you have multi line textboxes that need to allow the enter key add an attribute to the control as follows.

Me.txtProfAssessmentSummary.Attributes.Add("AllowKeypress", "true")


To conditionally enable the function use the following code.

Dim scriptstr As String = "document.onkeypress = EscapeKeys;"
ScriptManager.RegisterStartupScript(Me, Me.Page.[GetType](), "mykey", scriptstr, True)

To conditionally disable the function use the following code.

Dim scriptstr As String = "document.onkeypress = null;"
ScriptManager.RegisterStartupScript(Me, Me.Page.[GetType](), "mykey", scriptstr, True)

