通过在经典asp中按Enter键,onChange事件无法正常工作
问题描述:
在下面的代码片段中,如果我在文本框中输入详细信息后按输入,则onChange事件无法正常工作。但是如果我在文本框中输入详细信息后单击页面,则事件正常。
s = s&< input type =text name =xyzsize =1önChange=return abc(this.form,1)value =&pageno&style =border:1px solid#C0C0C0; padding:1 ; font-family:Arial; font-size:8pt>
谢谢
In the below code snippet onChange event is not working if I am pressing 'enter' after putting details in the text box. But the event is working correctly if I m clicking on the page after entering the details in the textbox.
s=s&"<input type=""text"" name=""xyz"" size=""1"" önChange=""return abc(this.form,1)"" value=" & pageno &" style=""border: 1px solid #C0C0C0; padding: 1; font-family:Arial; font-size:8pt"">
Thanks
答
单击enter并使用JavaScript回发时使用EnterEvent来捕获事件,该回发使用按钮的id值将你带到cs页面
< asp: textbox id =TextBox1clientidmode =Staticrunat =serveronkeypress =return EnterEvent(event)xmlns:asp =#unknown>
< asp:button id =Button1runat =serverstyle =display:nonetext =Buttonxmlns:asp =#unknown>
Use EnterEvent to capture the event when enter is clicked and using JavaScript postback which uses the id value of the button which ll take u to the cs page
<asp:textbox id="TextBox1" clientidmode="Static" runat="server" onkeypress="return EnterEvent(event)" xmlns:asp="#unknown">
<asp:button id="Button1" runat="server" style="display:none" text="Button" xmlns:asp="#unknown">
function EnterEvent(e) {
if (e.keyCode == 13) {
__doPostBack('<%=Button1.UniqueID%>', "");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
谢谢Arjun,
我以不同的方式使用了你的建议而且它有效。我使用onchange和onkeypressed事件如下:
s = s&< input type =textname =xyzsize = 1önChange=返回abc(this.form,1)onkeypress =xyz(e)>
函数xyz(a ,e,1)
{
if(e.keyCode == 13)
{
abc( a,1);
}
}
Thanks Arjun,
I used your suggestion in a different way and it worked. I used both onchange and onkeypressed event as below:
s=s&"<input type=""text"" name=""xyz"" size=""1"" önChange=""return abc(this.form,1)"" onkeypress=""xyz(e)"">
function xyz(a,e,1)
{
if(e.keyCode==13)
{
abc(a,1);
}
}