string userAD = string.Empty;
foreach (GridViewRow row in this.grdChooseUser.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("rbChecked");
if (cb != null && cb.Checked)
{
Label labAdAccount = (Label)row.FindControl("labAdAccount");
userAD = labAdAccount.Text.Trim();
break;
}
}
userAD = userAD.Replace("//", "%5C");
Page.ClientScript.RegisterStartupScript(GetType(), "message", "<Script>window.opener.document.all('" + clientID + "').value=unescape('" + userAD + "');window.close();</Script>");
}
类似于以上的情形。userAD得到为a/b 直接用脚本赋值给父窗口时,会乱码或出错。原因一定是转义字符出错。
解决方法 将“//”转义字符替换为"%5C", 在赋值的时候,用unescape方法转化为//。
唉,在这小事上浪费了2个小时