您的位置:首页 > Web前端 > JavaScript

如何在asp.net使用Javascript

2011-12-09 14:18 525 查看
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()");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: