ASP.NET网页一般加了母版页那个控件ID就会发生变化.其实这个ASP.NET有这个方面的解决方法:
document.getElementById("<%=你的服务器控件.ClientID%>").//是ClientID而不是ID
前台:
<script type="text/javascript">
function CheckID() {
var obj = document.getElementById("<%=tbx_ID.ClientID%>");
var fieldID = obj.value;
if (fieldID == "folder") {
alert("ID不能等于folder,请重新输入!");
obj.value = "";
obj.focus();
}
}
</script>
后台:
protected void Page_Load(object sender, EventArgs e)
{
Session["RegistrationTitle"].ToString();//标题
Session["Folder"].ToString();//文件夹名
if (Session["ResultList"]!=null)
{
Session["ResultList"].ToString();//字段信息
}
if (!IsPostBack)
{
//bind control type
this.rbl_Tyle.DataSource = Enum.GetNames(typeof(Common.InfoControlType));
this.rbl_Tyle.DataBind();
this.cbl_Validators.DataSource = Enum.GetNames(typeof(Common.ValidatorType));
this.cbl_Validators.DataBind();
this.tbx_ID.Attributes.Add("onblur", "CheckID()");
}
}