我在頁面上有3個LinkButton和1个GridView,后台代码如下,前台全部自动生成的代码。
现在的问题是在IE中(IE6、IE7都试过)当页面第一次进入,所有的JavaScript都可以使用,一切正常使用。但当页面刷新过后,JavaScript全部不能用,点LinkButton全没反应了。
GridView1添加的双击事件能弹出窗口,但在弹出窗口中进行操作无效(在弹出窗口中对数据进行编辑)。
但使用Firefox不会出现上面的情况。
找了半天,始终找不到问题出现在哪里,请各位大侠帮忙找一下错误。
public partial class DepEdit : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetDep();
}
} /// <summary>
/// 綁定部門
/// </summary>
private void GetDep()
{
Dep d = new Dep();
this.GridView1.DataSource = d.DepQuery ();
this.GridView1.DataBind();
this.GridView1.Columns[0].ItemStyle.Width = 10;
this.GridView1.Columns[2].ItemStyle.Width = 200;
}
protected void lbn_Del_Click(object sender, EventArgs e)
{
try
{
string DepIDs = string.Empty;
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox cbx = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbx.Checked == true)
{
DepIDs = DepIDs + ',' + this.GridView1.DataKeys[i].Value.ToString(); }
} if (string.IsNullOrEmpty(DepIDs))
{
ClientScript.RegisterStartupScript(Page.GetType(),
"js1", "alert('請選擇刪除項目!');", true);
}
else
{
DepIDs = DepIDs.Substring(1);
Dep d = new Dep(); string[] strDepID = DepIDs.Split(',');
for (int i = 0; i < strDepID.Length; i++)
{
if (d.IsDepID(Convert.ToInt32 (strDepID[i])))
{
ClientScript.RegisterStartupScript(this.GetType(),
"js2", "alert('存在子項目,如需刪除,請先刪除其子項目!');",true);
return;
}
} d.DepDel(DepIDs); ClientScript.RegisterStartupScript(this.GetType(),
"js3", "alert('刪除成功!');",true);
ClientScript.RegisterStartupScript(this.GetType(),
"js4", "window.location.href=window.location.href;",true);
}
}
catch (Exception)
{ }
}
protected void lbn_Add_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(),
"js5", "window.open('DepInfo.aspx',null,'height = 150,width =250,status = no,left=500,top=300,toolbar = no,menubar = no,location = no','');",true);
}
protected void lbn_Edit_Click(object sender, EventArgs e)
{
string DepID = string.Empty;
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
CheckBox cbx = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbx.Checked == true)
{
DepID =this.GridView1.DataKeys[i].Value.ToString();
break;
}
} if (string.IsNullOrEmpty(DepID))
{
ClientScript.RegisterStartupScript(this.GetType(),
"js6", "alert('請選擇編輯項目!');",true);
return;
}
ClientScript.RegisterStartupScript(this.GetType(),
"js7", "window.open('DepInfo.aspx?DepID="
+ DepID + "',null,'height = 150,width =250,status = no,left=500,top=300,toolbar = no,menubar = no,location = no','');",true);
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
GetDep();
} protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string js = "window.open('DepInfo.aspx?DepID="
+ GridView1.DataKeys[e.Row.RowIndex].Value.ToString()
+ "',null,'height = 150,width =250,status = no,left=500,top=300,toolbar = no,menubar = no,location = no','')"; e.Row.Attributes.Add("ondblclick", js);
e.Row.Attributes.Add("onmouseover", "currentcolor = this.style.backgroundColor;this.style.backgroundColor='#D2DCC5'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = currentcolor");
}
}
}
假设将这个网页发布,发布出来的URL为:http://10.148.8.10/dep;使用这个URL访问不会出现任何问题。我在SharePoint网站上使用“頁面檢視器網頁組件”把这个URL连接过去。在SharePoint网站上访问就出现了前面我描述的问题。如果先使用http://10.148.8.10/dep访问没有任何问题,不关闭这个页面,然后在SharePoint网站上访问并刷新,SharePoint网站上这个页面出现问题,这时返回刚才打开的http://10.148.8.10/dep,又会出现问题。