控件ID问题

 有时候运行程序的时候,可能ID会变,使你对原来ID的操作没用.当你发现这种问题时,可以查看页面的source,看看ID变没变.如下代码(不能运行,只是给示范用,比较乱):

ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ Page Language="C#" AutoEventWireup="true" CodeFile="ProjectIntro.aspx.cs" Inherits="DMaP.UserInterface.ProjectIntro"  %>
ExpandedBlockStart.gifContractedBlock.gif
<% dot.gif @ Register Src="ProjectIntro1.ascx" TagName="intro" TagPrefix="uc1"  %>
ExpandedBlockStart.gifContractedBlock.gif
<% dot.gif @ Register Src="ProjectIntro2.ascx" TagName="intro" TagPrefix="uc2"  %>
None.gif
< html  xmlns ="http://www.w3.org/1999/xhtml"   >
None.gif
< head  runat ="server" >
None.gif    
< title >
None.gif        
< asp:localize  runat ="server"  text ="<%$ Resources:PageTitle %>" ></ asp:localize >
None.gif    
</ title >
None.gif    
< link  href ="css/normal.css"  type ="text/css"  rel ="stylesheet" />
None.gif    
< link  href ="styles/ProjectIntro.css"  type ="text/css"  rel ="stylesheet" />
None.gif
</ head >
ExpandedBlockStart.gifContractedBlock.gif
< script  language ="javascript"  type ="text/javascript" > dot.gif
InBlock.gif
function menu1MouseOver()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    document.getElementById('intro1').className 
= "InputShow";
InBlock.gif    document.getElementById('intro2').className 
= "InputHidden";
InBlock.gif    document.getElementById('menu1').className 
= "menuSelect";
InBlock.gif    document.getElementById('menu2').className 
= "menuRelease";
InBlock.gif    document.getElementById('lblIntro2').className 
= "fontMouseRealse";
InBlock.gif    document.getElementById('lblIntro1').className 
= "fontMouseOver";
InBlock.gif    
return false;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
function menu2MouseOver()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    document.getElementById('intro1').className 
= "InputHidden";
InBlock.gif    document.getElementById('intro2').className 
= "InputShow";
InBlock.gif    document.getElementById('menu1').className 
= "menuRelease";
InBlock.gif    document.getElementById('menu2').className 
= "menuSelect";
InBlock.gif    document.getElementById('lblIntro2').className 
= "fontMouseOver";
InBlock.gif    document.getElementById('lblIntro1').className 
= "fontMouseRealse";              
InBlock.gif    
return false;
ExpandedBlockEnd.gif}

None.gif
</ script >
None.gif
< body  onload ="javascript:menu1MouseOver()" >
None.gif    
< form  id ="Form1"  runat ="server"  method ="post" >
None.gif        
< table  cellspacing ="0"  cellpadding ="0"  border ="0"  class ="MainTable" >
None.gif            
< tr >
None.gif                
< td >
None.gif                    
< div  id ="divBreadCrumb" >
None.gif                        
< asp:Image  ID ="Image1"  runat ="server"  ImageUrl ="~/image/arrows.gif"   />
None.gif                        
< span  class ="CurrentPage" >
None.gif                            
< asp:Localize  ID ="Localize3"  runat ="server"  Text ="<%$ Resources:DMaP, CurrentPage  %>" ></ asp:Localize ></ span >
None.gif                        
< span  class ="CurrentPageInfo" >
None.gif                            
< asp:Localize  ID ="Localize4"  runat ="server"  Text ="<%$ Resources: ProjectIntro  %>" ></ asp:Localize ></ span >
None.gif                    
</ div >
None.gif                
</ td >
None.gif            
</ tr >
None.gif            
< tr >< td > &nbsp; </ td ></ tr >
None.gif            
< tr >
None.gif                
< td >
None.gif                    
< table  cellspacing ="0"  cellpadding ="0"  style ="width:100%; padding: 5px; " >
None.gif                        
< tr >
None.gif                            
< td  id ="menu1"  class ="menuSelect"  onmousemove ="menu1MouseOver()"  onclick ="menu1MouseOver()" >                                 
None.gif                                
< asp:Label  ID ="lblIntro1"  runat ="server"  Text ="<%$ Resources: lbIntro1  %>"  CssClass ="fontMouseOver" ></ asp:Label >
None.gif                            
</ td >
None.gif                            
< td  id ="menu2"  class ="menuRelease"  onmousemove ="menu2MouseOver()"  onclick ="menu2MouseOver()" >
None.gif                                
< asp:Label  ID ="lblIntro2"  runat ="server"  Text ="<%$ Resources: lbIntro2  %>" ></ asp:Label >
None.gif                            
</ td >
None.gif                            
< td  id ="menu3"  style ="border-bottom:solid 1px #95BEE4; width:40%;" > &nbsp; </ td >
None.gif                        
</ tr >
None.gif                    
</ table >
None.gif                
</ td >
None.gif            
</ tr >
None.gif            
< tr  id ="intro1"  runat ="server" >
None.gif                
< td  class ="mainIntroText" >
None.gif                    
< uc1:intro  ID ="ProIntro1"  runat ="server"   />
None.gif                
</ td >
None.gif            
</ tr >
None.gif            
< tr  id ="intro2"  runat ="server" >
None.gif                
< td  class ="mainIntroText" >
None.gif                    
< uc2:intro  ID ="ProIntro2"  runat ="server"   />
None.gif                
</ td >
None.gif            
</ tr >             
None.gif        
</ table >
None.gif    
</ form >
None.gif
</ body >
None.gif
</ html >
None.gif

这代码的作用是通过MouseOver事件进行交替显示,但如果把这代码放到<asp:Content ></asp:Content>中的话,会自动在有 runat="server" 的控件的ID前加上"ctl00_ContentPlaceHolder1_",你把代码放到<asp:WizardStep></asp:Wizard>,则会加上"Wizard1_".

转载于:https://www.cnblogs.com/lovemyth/archive/2007/01/30/635053.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值