![asp按钮 表单验证](https://img-blog.csdnimg.cn/img_convert/8d2e59a719c3405770b1d09c4ef9dff1.png)
asp按钮 表单验证
I lot of great ideas came in the discussion about How to create a Default "Enter" Button for Forms/PostBacks.
在关于如何为Forms / PostBacks创建默认“ Enter”按钮的讨论中,我想到了很多很棒的主意。
There are a number of good solutions, here they are collected, as well as an additional one from Dino Esposito.
这里收集了许多好的解决方案,还有Dino Esposito的其他解决方案。
Similar to my idea, add a hidden EVENTTARGET, Darrell suggests to use the ClientID:Page.RegisterHiddenField("__EVENTTARGET", btnSearch.ClientId) - Darrell Norton
与我的想法类似,添加一个隐藏的EVENTTARGET,Darrell建议使用ClientID: Page.RegisterHiddenField(“ __ EVENTTARGET”,btnSearch.ClientId)-Darrell Norton
Jeff uses a JavaScript function and adds an onkeydown handler to the text box's attributes:
Jeff使用JavaScript函数,并将onkeydown处理函数添加到文本框的属性中:
Client-Side function:
客户端功能:
function AnyInput_KeyDown (e, target)
函数AnyInput_KeyDown(目标)
{ if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
{if(((e.which && e.which == 13)||(e.keyCode && e.keyCode == 13))
{ __doPostBack(target, ''); return false; } return true; }
{__doPostBack(target,)); 返回false; 返回true; }
Caller: onkeydown -> "AnyInput_KeyDown(event,'btnSearch');" -
调用者:onkeydown->“ AnyInput_KeyDown(event,'btnSearch');” --
Brian suggests Andy Smith's DefaultButton control.
Gerry Heidenreich has some VB.NET code on his site that rolls the above ideas into the Page_Load.
Phil Manijak suggests chaining events like:private void SearchBox_TextChanged(object sender, EventArgs e) {
Phil Manijak建议链接事件,例如: 私人无效SearchBox_TextChanged(object sender,EventArgs e){
// Pass the event along, as if it were a button click.
//传递事件,就好像单击按钮一样。
this.SearchButton_Click(sender, e); }
this.SearchButton_Click(sender,e); }
Matt Berther has a great fix on his site that involves just adding a hidden text box with no name.
Here's a great solution from Dino Esposito that takes the form of a Smart Text Box Server Control. PostTextBox.txt (5.57 KB)
这是Dino Esposito提供的出色解决方案,采用智能文本框服务器控件的形式。 PostTextBox.txt(5.57 KB)
asp按钮 表单验证