tempad
Readygo技术搜索引擎 >>项目管理 >> 光標定位的問題:document.getElementById(...) 是null或不是一個物件

光標定位的問題:document.getElementById(...) 是null或不是一個物件

Readygo技术搜索引擎 网络搜索 efish 2008-1-17 4:58:31

光標定位的問題:document.getElementById(...) 是null或不是一個物件

楼主derek()2004-03-12 10:31:13 在 .NET技术 / ASP.NET 提问

代碼如下,   執行時出現錯誤.   我是想在用戶按下datagrid中的Edit   按鈕後,   光標定位在其中一cell  
   
  private   void   DataGrid1_ItemDataBound(object   sender,  
  System.Web.UI.WebControls.DataGridItemEventArgs   e)  
      {  
        this.DataGrid1.Width=500;  
   
        e.Item.Cells.Width=60;  
        e.Item.Cells.Width=30;  
        e.Item.Cells.Width=80;  
        e.Item.Cells.Width=80;  
        e.Item.Cells.Width=80;  
        e.Item.Cells.Width=70;  
   
        if(e.Item.ItemType==ListItemType.EditItem)  
        {  
          ((TextBox)e.Item.Cells.Controls).Width=80;  
          ((TextBox)e.Item.Cells.Controls).Width=80;  
          ((TextBox)e.Item.Cells.Controls).Width=80;  
          ((TextBox)e.Item.Cells.Controls).Width=70;  
          //分別用以下兩種調用方式  
          //1   ---     this.SetFocus(((TextBox)e.Item.Cells.Controls));  
          //2   ---     this.SetFocus(e.Item.Cells.Controls);  
        }  
      }  
   
      private   void   SetFocus   (Control   controlToFocus)  
      {  
        StringBuilder   scriptFunction=new   StringBuilder();  
        string   scriptClientId;  
        scriptClientId   =   controlToFocus.ClientID;  
        scriptFunction.Append("<script   language="javascript">");  
        scriptFunction.Append("document.getElementById("");  
        scriptFunction.Append(scriptClientId);  
          //scriptClientId的值分別是  
        //調用方式1時---DataGrid1__ctl2__ctl3  
        //調用方式2時---DataGrid1__ctl3__ctl3  
        scriptFunction.Append("").focus();");  
        scriptFunction.Append("</script>");  
        RegisterStartupScript("focus",   scriptFunction.ToString());           //出現錯誤  
  說   "document.getElementById(...)"   是null或不是一個物件  
      }  
  问题点数:100、回复次数:12Top

1 楼derek()回复于 2004-03-15 17:39:44 得分 0

net_lover:  
          在html里為   body加上   runat=server   id="isok"   後,   在c#代碼編輯器里還是不能直接引用,說:   The   type   or   namespace   name   "rightsconfig"   could   not   be   found   (are   you   missing   a   using   directive   or   an   assembly   reference?)  
          請問如何用?  
   
   
  reqperwu   &   2002pine:   沒用模板,所以請問沒用模板第請況下應該如何做  
   
  vabug:  
        document.getElementByTagName("text").focus()     物件不支援此屬性或方法Top

2 楼SVG(ben)回复于 2004-03-17 11:48:37 得分 15

修改一下   SetFocus   的接口参数了.  
   
  用   table.rows.cells.childNodes.focus();   的js   方法来实现   focusTop

3 楼Lostinet(每晚 8:00 见)回复于 2004-03-17 11:55:34 得分 15

WebControl的ID没有指定的情况下,是不会自动生成客户端的id的.  
  Top

责任编辑: efish 参与评论 查找更多:
相关文章
一个奇怪的问题: 一个奇怪的问题:
DLL + Sql (C/S)怎么开发dll及客户端怎么连接databa… DLL + Sql (C/S)怎么开发dll及客户端怎么连接database呀??? 急呀....
请问一个apache soap与tomcat整合的问题 请问一个apache soap与tomcat整合的问题
客户端输入法的控制方法 客户端输入法的控制方法
ACCESS中的外联接:FROM jibeng left join diaochu … ACCESS中的外联接:FROM jibeng left join diaochu on jibeng.档案编号=diaochu.档案编号 left join diaoru on jibeng.档案编号=diaoru.档案编号 为什么不行…
运行webform是出错不原因!请指教 运行webform是出错不原因!请指教
后缀是tdb的文件用什么数据库打开 后缀是tdb的文件用什么数据库打开
写了一个组件,其中的方法耗时大,且方法中有不能使… 写了一个组件,其中的方法耗时大,且方法中有不能使用Application.ProcessMessages语句,有何解?如果我要加入进度条,如何加?
谁能提供ActiveReports 报表组件的中文说明 100分… 谁能提供ActiveReports 报表组件的中文说明 100分???
copy to 命令? copy to 命令?
2秒记住本站域名

玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的readygo.com.cn

分类导航
Readygo技术搜索引擎