C#,webform,用代码后台添加的input控件,没有加“runat=server",当dropdownlist控件选取相应的值后,要求焦点自动跳到该input控件上,我在doopdownlist控件的SelectedIndexChanged事件里,加入如下代码:
this.Page.RegisterStartupScript("", " <script>document.getElementById('ip2_1').focus();</script>");其中,ip2_1为input文本控件的ID。
将此页面文件xxx1.aspx设为起始页,单独运行此页面调试时,input能得到焦点。但在框架集里运行调试时,input却无法得到焦点。为什么啊??此问题已困扰两天,恳请高手指教!!

解决方案 »

  1.   

    框架集是iframe还是用户控件,如果是用户控件,input中的id可以发生改变,你查看下源代码就知道了
      

  2.   

    补充一下:我在doopdownlist控件的SelectedIndexChanged事件里加入以下代码给input赋值,能成功运行并使该文本控件得到相应的值:
    this.Page.RegisterStartupScript("", "<script>document.getElementById('ip2_1').value='"+ip1+"';document.getElementById('ip2_2').value='"+ip2+"';document.getElementById('ip2_3').value='"+ip3+"';document.getElementById('ip2_4').value='"+ip4+"';</script>");
      

  3.   

    简单点说,就是当dropdownlist控件选取一个值后,一个文本框控件得到焦点 的问题
    单独运行该页面文本框控件能得到焦点 但是在iframe框架里运行时,文本框控件却无法获得焦点,求高手指点!!
      

  4.   

    但是在iframe框架里运行时,文本框控件却无法获得焦点你js 是写在那里的 iframe 内  还是 iframe 外
      

  5.   

    写在doopdownlist控件的SelectedIndexChanged事件里
      

  6.   

    doopdownlist控件 在 iframe 内  还是 iframe 外
      

  7.   

    this.Page.RegisterStartupScript你用的是 03 么-----------------------------
    在iframe 内  设置iframe 外的 html 元素 是么脚本这样写 document
    =>
     parent.document  or top.document
      

  8.   

    parent.document  or top.document 
    都试过了 仍不行
    string ip1=this.Page.Request.Form["xx1"].ToString();
    this.Page.RegisterStartupScript("", "<script>document.getElementById('ip2_1').value='"+ip1+"'; script>");
    用以上语句可以赋值,为什么用document.getElementById('ip2_1').focus();却得不到焦点呢
      

  9.   

    没有执行其它语句,因为将该页面设为起始页,单独调试时,通过以下语句this.Page.RegisterStartupScript("", " <script>document.getElementById('ip2_1').focus();document.getElementById('ip2_1').value='"+ip1+"'; script>"); 
    input 是可以得到焦点的在框架里运行,却得不到焦点我用的是03,还得请高手继续指教啊
      

  10.   

    通过别的方式解决了,但还是要感谢Sandy945,结贴了。