This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 有个傻问题,ASP.net的一个button,想设置它为enter键的default event,怎么做?vb.net。谢谢!
-goldsky(泥锅泥碗泥滚蛋);
2004-2-2
(#1587323@0)
-
在Page_Load里写 button.select应该行吧
-vega_lee(天津の包子.NET);
2004-2-2
(#1587361@0)
-
不行。没有button.select,应该和accesskey有关。
-goldsky(泥锅泥碗泥滚蛋);
2004-2-2
(#1587368@0)
-
有点糊涂, 你是不是说你按enter的时候, 相当于click那个button?偶很菜的。
-henhen(哼哼,生日快乐!);
2004-2-2
(#1587373@0)
-
是这意思,偶也很菜呀
-goldsky(泥锅泥碗泥滚蛋);
2004-2-2
(#1587379@0)
-
You need to create a function and call it from in page_load or wherever you want:private void setFocus( System.Web.UI.Control ctrl )
{
string s = "<SCRIPT language='javascript'>document.getElementById('" + ctrl.ID + "').focus() </SCRIPT>";
this.RegisterStartupScript( "focus", s );
}
-wjiaca(WSY);
2004-2-2
{226}
(#1587371@0)
-
也就时说,vb.net不行,一定要用javascript?
-goldsky(泥锅泥碗泥滚蛋);
2004-2-2
(#1587378@0)
-
right in web application
-wjiaca(WSY);
2004-2-2
(#1587380@0)
-
谢谢
-goldsky(泥锅泥碗泥滚蛋);
2004-2-2
(#1587384@0)
-
I think this focus will be lost after you input anything in the textbox.
-hillxie(我叫不紧张);
2004-2-2
(#1587389@0)
-
不紧张,你说对了,我怎么解决?忘赐教:)
-goldsky(泥锅泥碗泥滚蛋);
2004-2-2
(#1587403@0)
-
So far I have no better idea than my another post, maybe somebody else will have one.
-hillxie(我叫不紧张);
2004-2-2
(#1587416@0)
-
you're right, if you want a button to become default button after entering something on the page, you have to do something else.
-wjiaca(WSY);
2004-2-2
(#1587408@0)
-
Make this button the first button in the form
-hillxie(我叫不紧张);
2004-2-2
(#1587381@0)
-
it works. any other idea?
-henhen(哼哼,生日快乐!);
2004-2-2
(#1587443@0)
-
FYI:
-hillxie(我叫不紧张);
2004-2-2
{1653}
(#1587450@0)
-
it works.private void TextBox1_TextChanged(object sender, System.EventArgs e)
{
SetFocusControl("Button3");
}
public void SetFocusControl( String ControlName)
{
String script= @"<script language="+"\"javascript\"" + ">" + " var control = document.getElementById(\"" + ControlName + "\");" + " if( control != null ){control.focus();}" + "</script>";
Page.RegisterStartupScript("Focus", script);
}
-henhen(哼哼,生日快乐!);
2004-2-2
{465}
(#1587519@0)
-
高手高手高高手!谢!
-goldsky(泥锅泥碗泥滚蛋);
2004-2-2
(#1587541@0)
-
Yes, they are 高手
-hillxie(我叫不紧张);
2004-2-2
(#1587624@0)
-
http://www.schmiddy.net/blog/2003/09/aspnet_default_.html
-hardywang(Hardy);
2004-2-2
(#1587495@0)
-
A good article for this, don't forget to check the discussion for the article. (it also mentions the solution Hardy post) http://www.allasp.net/enterkey.aspx
-hillxie(我叫不紧张);
2004-2-2
(#1587637@0)
-
谢谢, 跟你学了很多。:))
-henhen(哼哼,生日快乐!);
2004-2-2
(#1587661@0)
-
是问题问的好,加上老板下午没派活给我,就跟着长了长见识。
-hillxie(我叫不紧张);
2004-2-2
(#1587685@0)
-
希望你老板每天给你留点时间,偶们跟着沾光。:))
-henhen(哼哼,生日快乐!);
2004-2-2
(#1587697@0)
-
是喽
-goldsky(泥锅泥碗泥滚蛋);
2004-2-2
(#1587666@0)