我在我的aspx頁面中有一箇中繼器控件,並且在那個頁面中我放置了複選框。當用戶選中此框時,我想重定向到一個頁面。我已經寫了一個JavaScript也執行此操作如下:如何動態地將參數傳遞給javascript
JS:
function update(eid) {
window.location("Events.aspx?eid="+eid);
}
下面是代碼的方法後面:
protected void rptEventReminder_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
CheckBox cbx = e.Item.FindControl("chkComplete") as CheckBox;
Label lbl = e.Item.FindControl("lblEid") as Label;
if (cbx != null && lbl !=null)
{
Int64 eid = Convert.ToInt64(lbl.Text);
cbx.Attributes.Add("onclick", "update(eid);");
}
}
,我想過去EID這因爲參數是數據庫中唯一的。
JavaScript錯誤我得到的是:
JavaScript runtime error: 'eid' is undefined
試試這個:cbx.Attributes.Add(「onclick」,「update('」+ eid +「');」); –