RegisterStartUpScript 和 RegisterClientScriptBlock 的差異

使用RegisterStartUpScript 時,該段Script會被註冊在</from>的結尾前,而使用RegisterClientScriptBlock ,該段script會被註冊在<form>的結尾後。

範例RegisterClientScriptBlock:
<form name=”form1″ method=”post” action=”RegisterTest.aspx” id=”form1″>
<script>document.getElementById(‘TextBox1’).focus();</script>
    <div>
<input name=”TextBox1″ type=”text” id=”TextBox1″ /></div>
<div>
</form>

範例RegisterStartUpScript:
<form name=”form1″ method=”post” action=”RegisterTest.aspx” id=”form1″>
    <div>
<input name=”TextBox1″ type=”text” id=”TextBox1″ /></div>
<div>
<script>document.getElementById(‘TextBox1’).focus();</script>
</form>

所以,轉址的程式可以用RegisterClientScriptBlock,在前面就產出SCRIPT,
但是有關資料驗證的程式就必須使用RegisterStartUpScript,避免找不到物件。

by mhchen15 on 4 12 月, 2012 in ASP.NET C#, Javascript, 程式 - Tags: ,
Tags: ,

There are no comments.

Name*: Website: E-Mail*:
XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>