需求;点击linkbutton能控制table的显示与隐藏//内置按钮
 function update()
  {
    alert("11");
    document.getElementById("table_add").style.display="";//隐藏table
    alert("22");
  }
  <asp:LinkButton ID="LinkButton1" runat="server" CommandName="update" CommandArgument='<%# Eval("id") %>'
                          OnClientClick="update()" >[修改]</asp:LinkButton>
 protected void Repeater_address_ItemCommand(object source, RepeaterCommandEventArgs e)
    {     
      if (e.CommandName == "update")
        {
            //int id = Convert.ToInt32(e.CommandArgument);
            //ShouHuoAddress add = new ShouHuoAddress();
            //add=UserBll.GetShouHuoAddressById(id); 
            //txt_address.Text = add.Address;
            //txt_email.Text = add.Email;
            //txt_mobile.Text = add.Mobile;
            //txt_phone.Text = add.Phone;
            //txt_ShouHuoName.Text = add.ShouHuoName;
            //txt_zip.Text = add.Zip;
            //Button1.Visible = false;
            //btn_update.Visible = true;
            //Response.Write("<script> document.getElementById('table_add').style.display='';</script>");
           
        }
    }我发现能输出11 跟22 那就说明执行了隐藏的JS,但是因为要执行ItemCommand里面的事件,直接刷新页面,table(默认隐藏)又被隐藏了。我把js输出在cs里面Response.Write(js脚本)。就会报错 说缺少对象。
请问如何解决

解决方案 »

  1.   

    加个ID,runat="server';
    findcontrol()
    估计就成了吧.
      

  2.   


     else if (e.CommandName == "update")
            {
                foreach (RepeaterItem  item in Repeater_address.Items)
                {
                    
                    Table t = new Table();
                    t=(Table)item.FindControl("table_add");
                    t.Visible = true;
                }
                      }报未将对象引用到实例
      

  3.   

    我是查找repeater外的table
    这样不行啊 我不该这样写  我这写成内循环查找了
      

  4.   

     ClientScript.RegisterStartupScript(e.GetType(), "myscript", "<script> document.getElementById(table).style.display='block';</script>");
    楼主 试试这个 如果还是不行的话 你就是刷新了页面了
      

  5.   

    经过各种写法 我还是写不出来 请问 事件内如何 查找到Table并且 控制显示
      

  6.   

    #4 方法解决  前提是前台的table要加ruant=“server”
      

  7.   


    Response.Write("<script> document.getElementById('table_add').style.display='';</script>");
    这句改为调用页面的一个js方法。Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>ShowTable();</script>");这个js方法就在你前台写好了