RegisterClientScriptBlock:
//判断是否已经注册clientScript键的客户端脚本
if (!ClientScript.IsClientScriptBlockRegistered("clientScript"))
{
string scriptString = "<script language=\"javascript\" type=\"text/javascript\">" +
"function doClick()" +
"{" +
"alert('Button Clicked');" +
"}" +
"</script>";
//如果没有注册,使用RegisterClientScriptBlock方法注册客户端脚本
ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", scriptString, false);
}
//将注册的客户端脚本绑定到按钮的客户端单击事件
btnClickMe.Attributes.Add("onclick", "doClick()");
RegisterOnSubmitStatement:
String scriptText = "return confirm('是否确认提交?')";
ClientScript.RegisterOnSubmitStatement(this.GetType(), "ConfirmSubmit", scriptText);
RegisterStartupScript:
ScriptManager.RegisterStartupScript(Page, this.GetType(), "focus", "<script>document.forms[0]['TextBox1'].focus();</script>",false);