每个页面有两三个server button, 想实现用户随时点击回车都是点击指定按钮(Next,Submit,etc.)
有的在用户控件里。
我觉得也只能在后台为指定按钮加script,因为按钮类型太多,还有的在用户控件里,但怎么加呢?
相当于实现客户端<body onkeydown="ClickNext(ctlID)">,因为Attribute是服务器控件的属性,body的onkeydown后台怎么加?
有的在用户控件里。
我觉得也只能在后台为指定按钮加script,因为按钮类型太多,还有的在用户控件里,但怎么加呢?
相当于实现客户端<body onkeydown="ClickNext(ctlID)">,因为Attribute是服务器控件的属性,body的onkeydown后台怎么加?
<html>
<head><script runat="server">void Page_Load(Object sender, EventArgs e)
{
xx.Attributes.Add("onclick","alert('xx')");
b.Attributes.Add("onkeydown","if(event.keyCode==13) document.all.xx.click()");
}
</script>
</head>
<body id=b runat=server>
<form runat=server>
<asp:Panel id=p runat=server/>
<asp:Textbox id=t1 runat=server/>
<asp:button id=b1 runat=server Text="b1"/>
<asp:button id=b3 runat=server Text="b2"/>
<asp:button id=xx runat=server Text="xx" />
</form>
</body>
</HTML>
System.Web.UI.HtmlControls.HtmlGenericControl b;
原理当然也是一样的,
在body中增加 onkeypress="keypress()"再添加js脚本:
function keypress()
{
if(event.keyCode==13)
{
Form1.button1.click();
}
}
再问一下,如果用<body id="body" runat="server> 然后后台
body.Attribute.add("onkeydown","ClickNextButton("+BtnNext.ID+")")
这样会有问题吗,因为代码好像可以简单点。
----
这样是不行的,windows的做法那是,web始终是会触发靠近文本框的一个按钮的。