如何设置焦点以控制以编程方式创建的(运行期间) [英] How to setfocus to control created programmatically (DURING RUN TIME)
问题描述
**** ASP.NET VB.NET 2010 *********
请帮我,我有一个超链接列表.如果按下单选按钮,我希望光标聚焦在我的超链接之一上
我试图用这个,但是没有运气
****ASP.NET VB.NET 2010 *********
Hi,
Kindly help me with this, I have a list of Hyperlink. If I press radio button I want my cursor to focus on one of my hyperlink
I tried to used this but no luck
Dim sScript As String = "<SCRIPT language='javascript'>document.getElementById('" & hlnkQNo.ID & "').focus();</script>"
'Page.RegisterStartupScript("controlFocus", sScript)
我也尝试了此操作,但同样,光标没有集中在我的链接ScriptManager1.SetFocus(hlnkQNo.ID)
上.
这是我想要的例子
超链接1
超链接2
超链接3
超链接3
超链接4
如果使用单击单选按钮,我想关注Hyperlink4
-请注意,所有控件都是动态创建的(在运行期间)
-请注意,所有控件都是动态创建的(在运行时)
I also tried this but the same, the cursor was not focus on my link ScriptManager1.SetFocus(hlnkQNo.ID)
.
Here is my example of what I want
Hyperlink1
Hyperlink2
Hyperlink3
Hyperlink3
Hyperlink4
if the use click the radio button i want to focus on Hyperlink4
--KINDLY NOTE THAT ALL CONTROLS ARE CREATED DYNAMICALLY (DURING RUNTIME)
-- Kindly note that all the controls are created dynamically (during runtime)
推荐答案
Hi.
可能hlnkQNo.ID只是服务器端ID,不能在javascript中使用.您可以使用hlnkQNo.ClientID从JS查找html元素.
玩得开心!
Hi.
Probably hlnkQNo.ID is only server side ID and it cannot be used in javascript. You can use hlnkQNo.ClientID to find your html element from JS.
Have fun!
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
hlnkQNo.Focus();
}
1.为单选按钮添加一个事件.
2.在此事件内为控件设置Focus.
1. Add an event for the radio button.
2. Set the Focus for the control inside this event.
这篇关于如何设置焦点以控制以编程方式创建的(运行期间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!