首页 新闻 会员 周边

框架网页控件获取焦点!!

0
悬赏园豆:50 [已解决问题] 解决于 2010-01-17 07:46

最近刚学,遇到了个问题,望高手能帮个忙!!

我有两个文件,一个main.aspx 一个WebForm1.aspx  ,WebForm1.aspx有两个控件,一个DropDownList1,一个TextBox1

main.aspx的 Html代码:

......

<frameset id="aa" cols="150,8,*">

   <frame name="left" scr="lefttree.aspx">

  <frame name="middle" scr="t_l.htm">

  <frame name="main" scr="WebForm1.aspx">

</frameset>

...

 

WebForm1.aspx.cs 代码也只加了

  private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
  {
   this.Page.RegisterStartupScript("","<script>document.getElementById('TextBox1').focus();</script>");
   }
  }

只运行WebForm1.aspx时,能实现DropDownList1改变,TextBox1获得焦点,但运行main.aspx却不能获得焦点,而且TextBox1点也点不进去了! 

还望各位高手给予指点!!

在线等!!!

问题补充: WebForm1.aspx的Html代码 <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <FONT face="宋体"> <asp:dropdownlist id="DropDownList1" style="Z-INDEX: 101; LEFT: 424px; POSITION: absolute; TOP: 160px" runat="server" AutoPostBack="True"> <asp:ListItem Value="123">123</asp:ListItem> <asp:ListItem Value="456">456</asp:ListItem> </asp:dropdownlist><asp:textbox id="TextBox1" style="Z-INDEX: 102; LEFT: 416px; POSITION: absolute; TOP: 240px" runat="server"></asp:textbox></FONT></form> </body>
拓海的主页 拓海 | 初学一级 | 园豆:148
提问于:2010-01-14 16:46
< >
分享
最佳答案
0

脚本应该在page_Load事件中注册

WebForm1.aspx.cs

 

protected void Page_Load(object sender, EventArgs e)
{
if (DropDownList1 != null)
{
DropDownList1.Attributes.Add(
"onchange", "document.getElementById('TextBox1').focus();");
}

}

 

收获园豆:50
邀月 | 高人七级 |园豆:25475 | 2010-01-14 17:08
顺便问一下,为什么单独运行WebForm1时,不用注册也能实现,而在框架网页里要注册呢?
拓海 | 园豆:148 (初学一级) | 2010-01-17 07:48
其他回答(2)
0

<asp:dropdownlist id="DropDownList1" style="Z-INDEX: 101; LEFT: 424px; POSITION: absolute; TOP: 160px" runat="server" AutoPostBack="True">
你这个控件都没有DropDownList1_SelectedIndexChanged这个事件,没想通它怎么来的

Ou lei | 园豆:619 (小虾三级) | 2010-01-14 17:08
0

在使用main.aspx的时候,我是这样做的:window.parent.main.document.Form1.TextBox1.focus();

你的错误应该是没有指定框架,这个顺序是窗口-框架-document-表单-内容,你没有指定框架,

也就是相当于window.document.Form1.TextBox1.focus();

中间少了一层,所以脚本不知道究竟该定位在哪个框架里面,理所当然就就不能获取焦点,我也是试了很多次才发现的!

当然不在main.aspx的时候因为没有框架所以不需要这么复杂的告诉脚本在哪里,它直接默认的就在父框架里面,所以可以脚本是正确的!

还有就是你也可以这样:window.parent.main.document.getElementById('TextBox1').focus();意思是一样的!

你按照这个思路修改一下你的脚本应该就可以了,希望可以帮到你!

lanvendar | 园豆:200 (初学一级) | 2010-01-14 17:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册