ASP.NET回车键 [英] ASP.NET Enter key
问题描述
我有一个母版页和基于该母版页上我创建了一个网页,一个文本框和两个验证为 RequiredValidator
和 RegularEx $ P控制$ pssionValidator
和一个的ValidationSummary
。
在pressing在文本框输入键,我预计双方的验证表明其对的ValidationSummary的errorMessage但那不是发生了什么,当我preSS页面上的按钮,它才会起作用。
根据这一页我包我的code与< ASP:面板>
和 DefaultButton
属性但它并没有解决问题。
HTTP://www.$c$cproject.com/KB/aspnet/aspnet_Enter_key_problem的.aspx
我想知道这里的问题是什么,是否有解决方法吗?
< ASP:内容ID =内容2ContentPlaceHolderID =日程地址搜索Maincontent=服务器> **< ASP:面板=服务器DefaultButton =EmailSend> **
<表样式=宽度:100%>
&所述; TR>
< ASP:的ValidationSummary ID =EmailValidation=服务器的CssClass =failureNotification
的ValidationGroup =EmailValidation/>
< / TR>
&所述; TR>
< TD风格=宽度:76px>
电子邮件:
< / TD>
< TD类=STYLE1>
< ASP:文本框ID =EmailForget=服务器WIDTH =244px>< / ASP:文本框>
< / TD>
&所述; TD>
< ASP:的RequiredFieldValidator ID =EmailRequiered=服务器的ControlToValidate =EmailForget
的CssClass =failureNotification的ErrorMessage =的RequiredFieldValidator的ValidationGroup =EmailValidation> * LT; / ASP:&的RequiredFieldValidator GT;
< ASP:RegularEx pressionValidator ID =EmailRegular=服务器的ControlToValidate =EmailForget
的CssClass =failureNotification的ErrorMessage =电子邮件要求
的ValidationGroup =EmailValidation> * LT; / ASP:RegularEx pressionValidator>
< / TD>
< / TR>
&所述; TR>
< TD风格=宽度:76px>
&安培; NBSP;
< / TD>
< TD类=STYLE1>
< ASP:按钮的ID =EmailSend=服务器文本=发送WIDTH =56px的ClientIDMode =静态/>
< / TD>
&所述; TD>
&安培; NBSP;
< / TD>
< / TR>
< /表>
**< ASP:面板> **
< / ASP:内容>
尝试添加该code
<脚本类型=文/ JavaScript的> 如果(document.addEventListener){//如果Firefox
document.addEventListener(键preSS,fireFoxHandler,真正的);
}其他{
document.attachEvent(的onkeyup,ieHandler);
} 功能fireFoxHandler(EVT){
如果(evt.key code == 13){
的document.getElementById(EmailSend),点击()。
}
} 功能ieHandler(EVT){
如果(evt.key code == 13){
的document.getElementById(EmailSend),点击()。
}
}< / SCRIPT>
找到这个解决方案 这里 。
(我没有在母版情景检查,请检查...)
I have a master page and based on that master page I created a page with a TextBox and two Validation controls for RequiredValidator
and RegularExpressionValidator
and one ValidationSummary
.
when pressing the enter key in TextBox, I expected that both validator show their errorMessage on validationSummary but thats not what happening it only works when I press the button on page.
According to this page I wrapped my code with <asp:panel>
and a DefaultButton
attribute but it didn't solve the problem.
http://www.codeproject.com/KB/aspnet/aspnet_Enter_key_problem.aspx
I want to know what the problem here is and whether there is any workaround?
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
**<asp:Panel runat="server" DefaultButton="EmailSend">**
<table style="width: 100%">
<tr>
<asp:ValidationSummary ID="EmailValidation" runat="server" CssClass="failureNotification"
ValidationGroup="EmailValidation" />
</tr>
<tr>
<td style="width: 76px">
Email:
</td>
<td class="style1">
<asp:TextBox ID="EmailForget" runat="server" Width="244px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="EmailRequiered" runat="server" ControlToValidate="EmailForget"
CssClass="failureNotification" ErrorMessage="RequiredFieldValidator" ValidationGroup="EmailValidation">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="EmailRegular" runat="server" ControlToValidate="EmailForget"
CssClass="failureNotification" ErrorMessage="email required"
ValidationGroup="EmailValidation">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td style="width: 76px">
</td>
<td class="style1">
<asp:Button ID="EmailSend" runat="server" Text="send" Width="56px" ClientIDMode="Static" />
</td>
<td>
</td>
</tr>
</table>
**<asp:Panel>**
</asp:Content>
Try adding this code
<script type="text/javascript">
if (document.addEventListener) {//if Firefox
document.addEventListener("keypress", fireFoxHandler, true);
} else {
document.attachEvent("onkeyup", ieHandler);
}
function fireFoxHandler(evt) {
if (evt.keyCode == 13) {
document.getElementById("EmailSend").click();
}
}
function ieHandler(evt) {
if (evt.keyCode == 13) {
document.getElementById("EmailSend").click();
}
}
</script>
Found this solution here. (I didn't check this in MasterPage scenario, please check...)
这篇关于ASP.NET回车键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!