protected void Page_Load(object sender, EventArgs e)
    {
         if (mes == "2" && action == "edit")
          {
            gq.Visible = false;
            zp.Visible = true;
            Button3.Text = "修改";
            SqlConnection myConn = new SqlConnection(conn);
            myConn.Open();
            string sql = ("select * from db24 where db1='" + id + "'AND id='"+ mes_id +"'");
            SqlCommand comm = new SqlCommand(sql, myConn);
            SqlDataReader rd = comm.ExecuteReader();
            //string pwd = this.txtPwd.Text;
            if (rd.Read())
            {
                zp_db2.Text=rd["db2"].ToString();            }
            myConn.Close();
}
    protected void Button3_Click(object sender, EventArgs e) 
    {
     if (action == "edit" && mes=="2")
        {
            SqlConnection myConn = new SqlConnection(conn);
            myConn.Open();
            string Sql = "update db24 set db2='"+zp_db2.Text+"' where db1='" + id + "' AND id='"+ mes_id +"'";
            SqlCommand com = new SqlCommand(Sql, myConn);
            SqlDataReader da = com.ExecuteReader();
            myConn.Close();
            Page.Response.Redirect("../login/main.aspx");
        }
    }
}
上面是代码~!!div的Visible初始属性都是"false",update的时候取不到zp_db2(这个是个textbox)的值了````
请大大们帮忙解决一下````这段代码没有错,我把update中的zp_db2换成别的变量都好用,感觉就是因为Visible="false"影响取值`````

解决方案 »

  1.   

    style.display="none";
    //style.display="block"
    這個可以避免上述問題
      

  2.   

    ible="false" 就找不到前台这个对象如果你用 style="display:none"这样就没问题了,这个只是样式的隐藏 
      

  3.   

    用style="display:none"的话 在if中怎么去控制它的显示与隐藏?
      

  4.   

    -.-
    div.style.display="none"; 
      

  5.   

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <script>
        function aa()
        {
            var b=document.getElementById('txtinput').value;
            alert(b);
        }
        
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div style="display:none">
        <input type="text" id="txtinput" runat="server" value="123" />
            </div>
        <input type="button" onclick="aa()" />
        </form>
    </body>
    </html>完全可以取值
      

  6.   

    -,- 俺是新手 用style="display:none" 会影响式样把```
    会出现占位吗
      

  7.   

    div.visable="false" 服务器编译后的html是不会发到client端的
    处理方法:
    1.<asp:hiddenField/>
    2.控制css:style="display:block"(可见)/style="display:none"(隐藏)
      

  8.   


    如:<div runat="server" id="dv">
          asdasdadasdasd  </div>后台:dv.Style.Add("display", "none"); 隐藏    dv.Style.Remove("display"); 显示      
      

  9.   

    请问用hiddenField的话protected void Page_Load(object sender, EventArgs e)
        {
             if (mes == "2" && action == "edit")
              {
                gq.Visible = false;
                zp.Visible = true;
                Button3.Text = "修改";
                SqlConnection myConn = new SqlConnection(conn);
                myConn.Open();
                string sql = ("select * from db24 where db1='" + id + "'AND id='"+ mes_id +"'");
                SqlCommand comm = new SqlCommand(sql, myConn);
                SqlDataReader rd = comm.ExecuteReader();
                //string pwd = this.txtPwd.Text;
                if (rd.Read())
                {
                    hidd_id.Value=zp_db2.Text=rd["db2"].ToString();            }
                myConn.Close();
    }
        protected void Button3_Click(object sender, EventArgs e) 
        {
         if (action == "edit" && mes=="2")
            {
                SqlConnection myConn = new SqlConnection(conn);
                myConn.Open();
                string Sql = "update db24 set db2='"+hidd_id.Value+"' where db1='" + id + "' AND id='"+ mes_id +"'";
                SqlCommand com = new SqlCommand(Sql, myConn);
                SqlDataReader da = com.ExecuteReader();
                myConn.Close();
                Page.Response.Redirect("../login/main.aspx");
            }
        }
    }
    是这么写吗````````
    没用过hiddenField -,- 请教了
      

  10.   

     hidd_id.Value=zp_db2.Text=rd["db2"].ToString();
    那就可以不用zp_db2.Text了
      

  11.   

    可以这样:ViewState["参数"]=rd["db2"].ToString();
    "update db24 set db2='"+ViewState["参数"].ToString()+"' where db1='" + id + "' AND id='"+ mes_id +"'";
      

  12.   

    还得用zp_db2.text 因为是个修改的过程 textbox里面得有值
      

  13.   

    visible=false后,这个控件是没有值可取的.如果要隐藏并可取值,可以用style.display="none"解决.
      

  14.   

    仔细看了你代码,发现大家都被你的提问误导了
    Page_Load里代码用if (!IsPostBack)
            { 
            }括起来,为其他不用改
      

  15.   

    load里的所有代码都用写在!IsPostBack 里?
      

  16.   

    嗷嗷~!!!!!
    明白了```````
    就读一次``````
    疯了 以前都会写 !IsPostBack的```就这次忘了`````郁闷 谢谢 BernardSun 指教~!