页面中的默认按钮 [英] Default Button in pages

查看:82
本文介绍了页面中的默认按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有多个内容页面的母版页,在内容页面中,我有一个用户控件,我想在用户控件中设置一个默认按钮.

有没有通用的方法可以做到这一点.即,我只希望编写一个函数,并且应在整个应用程序中使用该函数.

我为此付出了很多努力.请帮我做到这一点.

I have a master page which is having number of content pages, in content pages i have a user control, i want to set a default button in user control.

Is there any genric way to do this. i.e., i want only one function written and that function should be used through out the application.

I was struggling a lot on this. Please help me to do this.

推荐答案

您可以尝试以下方法:
在母版页中,定义一种方法来设置默认的Button.

有一个主面板,您可以在其中保留所有内容面板.现在,在母版页"加载中设置母板默认按钮.您可以在后面的母版页代码中获取内容页面的控件及其用户控件.找到并根据其他页面进行设置.

试试吧!
You can try something like:
In your master page, define a method to set the default Button.

Have a master panel inside which you keep all the content panels. Now, set the master panels default button in your Master Page load. You can get the controls of content page and it''s usercontrol in masterpage codebehind. Find it and set it according to different page.

Try it!


基本上,您将需要JavaScript.甚至面板的默认按钮处理也使用JavaScript.一旦克服了这个障碍,实际上就很容易了:

1)发明一个HTML属性,将其称为defaultbutton ="yes"
2)将该属性应用于用户控件中的相应按钮
如果您只有C#,则可以使用
MyButton.Attributes.Add("defaultbutton","yes");
3)在您的母版中放入一些jQuery或等效的jQuery,以将Enter按键附加到按钮的单击上.我建议将其附加到body.onkeypress上,因为无论焦点在页面上的什么位置,它都将触发.
Basically you are going to need JavaScript. Even the Panel''s default button handling uses JavaScript. Once you''re over that hurdle it''s pretty easy actually:

1) Invent an HTML attribute, let''s call it defaultbutton="yes"
2) Apply that attribute to the appropriate buttons in your user controls
if you only have C# you can use
MyButton.Attributes.Add( "defaultbutton", "yes" );
3) Put some jQuery, or equivalent, into your master to attach the Enter keypress to the button''s click. I recommend attaching to body.onkeypress cause it will fire no matter where the focus is on the page.


这篇关于页面中的默认按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆