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

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

我有两个文件,一个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点也点不进去了! 

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


慕码人8056858
浏览 651回答 2
2回答

小唯快跑啊

脚本应该在page_Load事件中注册WebForm1.aspx.cs&nbsp;protected void Page_Load(object sender, EventArgs e) &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (DropDownList1 != null) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DropDownList1.Attributes.Add("onchange", "document.getElementById('TextBox1').focus();"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;

慕慕森

asp:dropdownlist id="DropDownList1" style="Z-INDEX: 101; LEFT: 424px; POSITION: absolute; TOP: 160px" runat="server" AutoPostBack="True">你这个控件都没有DropDownList1_SelectedIndexChanged这个事件,没想通它怎么来的
打开App,查看更多内容
随时随地看视频慕课网APP