我之前问的一个问题,以为解决了,今天发现没有,重新发起:.net控制前台页面div样式。比如这个DIV的ID为showMsg。我给他指定了2个样式,一个showErrMsg,一个showSucessMsg 。做不同情况下提醒信息显示不同的样式效果。 我知道用JS可以实现,直接用.net后台代码部分,控制代码要怎么写吗?
<div id="showErrMsg" runat="server"> <asp:Label ID="lblErrMsg" runat="server" Text=""> </asp:Label> </div> 样式部分 
.showErrMsg 

padding:5px 5px 5px 25px; 
border:1px solid #00BE00; 
background:#E6FFE6  url(standard_msg_error.gif) 5px 5px no-repeat; 
color:#000; 
float:left; 
margin:0px; 
width:518px; 
} .showSucessMsg 

padding:5px 5px 5px 25px; 
border:1px solid #00BE00; 
background:#E6FFE6  url(standard_msg_ok.gif) 5px 5px no-repeat; 
color:#000; 
float:left; 
margin:0px; 
width:518px; 
} 这是我以前的一个问题,当时有人回答//更改为showErrMs样式
showMsg.Style.Add("class","showErrMs");
//更改为showSucessMsg样式
showMsg.Style.Add("class","showSucessMsg");
因为我当时直接定义了样式<div id="showErrMsg" runat="server" class="showErrMs"> <asp:Label ID="lblErrMsg" runat="server" Text=""> </asp:Label> </div> ,也没留意,今天发现了,去掉了定义后,发现后台控制的样式没起到控制效果,根本没效果....请知道的大侠告之~~急~~~~~~~~~ 

解决方案 »

  1.   

    这一般用js控制的.

    <input type="text" id="UserName"  onchange="CheckUserName();" value=""    />
    js:
    document.getElementById("UserName").className="showErrMs";这样就可以动态定义样式了.
      

  2.   

    两个DIV吧
    if(成功)
    {
    div1.visible=true;
    div2.visible=false;
    }
    else
    {
    div1.visible=false;
    div2.visible=true;
    }
      

  3.   

    写了个简单的示例,你看下吧.这个详细点:
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
       <style type="text/css">
       .tt{
          margin: 55px;
          }
         
       </style>
      <script type="text/javascript">
        function test3()
    {
    document.getElementById("Text1").className="tt";

    }
      
      
      </script>
       
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input id="Text1" type="text"  onfocus="test3()"  /></div>
        </form>
    </body>
    </html>
      

  4.   

    lZ行面的方法应该这样用
    showErrMsg.Style.Add("background-color","red");
    里面的参数不是用来添加class的
      

  5.   


    关键是我AJAX不是很熟悉,不然无法做到跟数据库互动。所以我选择了去服务端做判断,然后根据结果做不同样式的提示。继续等~~~~
      

  6.   

    showErrMsg.Attributes.Add("class", "showErrMsg");class 数div的属性 
      

  7.   

    class 是div的属性  所以用Attributes
    showErrMsg.Style.Add("","");  这个是添加css样式的  
      

  8.   

    试试这个:
    showMsg.Attribute.Add("class","showErrMs");
      

  9.   

    可以实现的。我以前的方法
     if (this.checkbox.Checked)
            {
                upimgbox.Style.Value = "display:block";
            }
            else if (!this.checkbox.Checked)
            {
                upimgbox.Style.Value = "display:none";
            }