我有 AJAX HTML 编辑器扩展器和页面顶部的文本框,它不是 HTML 编辑器扩展器的目标控件。
在 key-down 上有一个为上述文本框编写的 JavaScript 方法,但是每当我写入文本框并按 Enter 键时,就会调用另一个为图像按钮控件编写的 JavaScript 方法。我该如何解决?
文本框和图像按钮依次放置,AJAX HTML 编辑器扩展器放置在更新面板内。
我使用的是 IE11,会不会和 IE 版本有关?
这是我的代码示例:
<asp:Content ID="Content1" ContentPlaceHolderID="cphmain" runat="Server">
<script language="javascript" type="text/javascript">
Sys.Extended.UI.HtmlEditorExtenderBehavior.prototype._editableDiv_submit = function() {
//html encode
var char = 3;
var sel = null;
setTimeout(function() {
if (this._editableDiv != null)
this._editableDiv.focus();
}, 0);
if (Sys.Browser.agent != Sys.Browser.Firefox) {
if (document.selection) {
sel = document.selection.createRange();
sel.moveStart('character', char);
sel.select();
} else {
if (this._editableDiv.firstChild != null && this._editableDiv.firstChild != undefined) {
sel = window.getSelection();
//sel.collapse(this._editableDiv.firstChild, char);
}
}
}
//Encode html tags
//this._textbox._element.value = this._encodeHtml();
this._textbox._element.value = htmlDecode(this._textbox._element.value);
}
function htmlDecode(value) {
return $("<div/>").html(value).text();
}
</script>
<script type="text/javascript">
/**Here is the method called on pressing enter key in the text box click below**/
function GetCertificate(e, ctrl, len) {
if (ValidateAlphaNumericAndMaxLength(e, ctrl, len)) {
var keynum;
var keyname;
if (window.event) // IE
{
keynum = e.keyCode;
if (keynum == 13) {
ValidateID();
return false;
} else {
return true;
}
}
}
}
function ValidateID() {
var ipno = document.getElementById('<%=txtuhid.ClientID%>').value;
var txtlength = document.getElementById('<%=txtid.ClientID%>').value.length;
if (ipno == "" || txtlength < 6) {
ShowMsgBox('Certificate', 'Enter Valid ID ', 'OK', 'Information');
return false;
}
else
//__doPostBack('KEYDOWNUHID', 'ctl00_UpdatePanel2');
__doPostBack('ctl00_UpdatePanel2', 'KEYDOWNUHID');
}
/**Here is the method called on image button click below**/
function opensearchlCertificate(searchName, searchFilter, searchType) {
var Return;
var functionID, context, workStationID, orderType, iniFilter;
var userName = 2;
var featureName = -4;
functionID = 0;
context = null;
workStationID = 0;
orderType = "";
iniFilter = searchFilter;
var searchArgs = new Array(searchName, userName, featureName, functionID, context, workStationID, orderType, iniFilter);
Return = window.showModalDialog('../Shared/CommonSearchPage.aspx', searchArgs, "dialogWidth:800px; dialogHeight:500px;scroll:no;")
if (Return == null) {
return false;
}
var result = Return.Result;
var rowValueArray = Return.Result.split(",");
for (var rowValue in rowValueArray) {
//......
//...
}
}
</script>
<div style="height: 10px">
</div>
<div class="forminner">
<table cellpadding="0" border="0" cellspacing="0" width="100%">
<tr>
<td width="6%" nowrap="nowrap" class="label">
<asp:Label ID="lbluhid" runat="server" Text="UHID"></asp:Label>
<span class="requiredfield">*</span>
</td>
<td width="30%">
<!-- here we are entering input and after that press enter key -->
<asp:TextBox ID="txtid" runat="server" TabIndex="0" MaxLength="15" onkeydown="javascript:return GetMedicalCertificate(event, this, 20);"
CssClass="mandsearchtxtbox"></asp:TextBox>
<asp:ImageButton ID="imgBtnSearch" TabIndex="1" ImageUrl="~/images/blank.gif" Width="23"
Height="19" CssClass="imgsearch" runat="server" OnClientClick="javascript:return opensearchCertificate('MRDMedicalCertificatePatientSearch','','single');" />
</td>
<tr>
<tr>
<td colspan="4">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<%--<cc1:Editor ID="HtmlEditorMedicalCertificate" Width="99%" Height="200px" runat="server" />--%>
<asp:TextBox ID="txtEditor" TextMode="MultiLine" Width="99%" Height="200px" runat="server" onkeydown="javascript:return Editorkeydown(event, this);" />
<!-- Here is the html editor below -->
<ajaxToolkit:HtmlEditorExtender ID="HtmlEditorMedicalCertificate" EnableSanitization="false" DisplaySourceTab="true" TargetControlID="txtEditor" runat="server" ></ajaxToolkit:HtmlEditorExtender>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="txtEditor" />
</Triggers>
</asp:UpdatePanel>
</tr>
</table>
<div class="clear">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="imgBtnSearch" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
</div>
</asp:Content>