向页面拖一个Web控件<asp:Button ID="Button2" runat="server" Text="Button"/>在cs中: protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Button2.Attributes["Text"] = "fgfgfg";
        }
    }运行之后,为什么Button2的文本没有变化呢?

解决方案 »

  1.   

    protected void Page_Load(object sender, EventArgs e)    
    {       
       if (!Page.IsPostBack)       
       {            
        Button2.Attributes["value"] = "fgfgfg";
        或者 Button2.text="dfd";   
       }   
     }
      

  2.   


    就算是改成Button2.Attributes["value"] = "fgfgfg";
    也没对啊?是什么原因?
      

  3.   

    Attributes是html客户端标记的属性,不是服务器控件的属性!
    你的服务器Button2控件经asp.net处理后,会产生对应的html标签,
    <input type="submit" name="Button2" value="Button" id="Button2" />
    所以你应该Button2.Attributes["value"] = "fgfgfg";
      

  4.   


    Button2.Attributes["value"] = "fgfgfg";
    后居然是 <input type="submit" name="Button1" value="Button" id="Button1" value="123" />
    有两个value,而且显示的还是前者,等大神来回答了