需求;点击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脚本)。就会报错 说缺少对象。
请问如何解决
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脚本)。就会报错 说缺少对象。
请问如何解决
findcontrol()
估计就成了吧.
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;
}
}报未将对象引用到实例
这样不行啊 我不该这样写 我这写成内循环查找了
楼主 试试这个 如果还是不行的话 你就是刷新了页面了
Response.Write("<script> document.getElementById('table_add').style.display='';</script>");
这句改为调用页面的一个js方法。Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>ShowTable();</script>");这个js方法就在你前台写好了