protected void AlertMessage(string ScriptID, string Message)
{
string strScript = " <script language=\"javascript\">\n";
strScript += " alert(\"" + Message + "\");\n";
strScript += "</script>\n";
RegisterStartupScript(ScriptID, strScript);
}
{
string strScript = " <script language=\"javascript\">\n";
strScript += " alert(\"" + Message + "\");\n";
strScript += "</script>\n";
RegisterStartupScript(ScriptID, strScript);
}
● 使用 RegisterStartupScript 會將內容的 Javascript 產生在 </form> 上一行
● 使用 RegisterClientScriptBlock 會將內容的 Javascript 產生在 <form> 下一行
<body>
<form name="form1" method="post" action="TestRegisterJava.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTU5MTA2ODYwOWRkmbCuiO5HQUj5tuT4Q9q+cMWMGBo=" />
</div>
<script language="javascript">
alert("RegisterClient");
</script>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwK90vPBCQLs0bLrBgKM54rGBjWLoYUoxEu/x64qISF1ZSWFz2B9" />
</div>
<div>
<input name="TextBox1" type="text" id="TextBox1" />
<input type="submit" name="Button1" value="Button" id="Button1" /><br />
<span id="Label1">Label</span></div>
<script language="javascript">
alert("RegisterStart");
</script>
</form>
</body>
沒有留言:
張貼留言