控件ID问题

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

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


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

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

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

你可能感兴趣的:(问题)