Different between RegisterClientScriptBlock and RegisterStartupScript

 

RegisterClientScriptBlock Output

    <form name=”form1″ method=”post” action=”Default.aspx” id=”form1″>

<div>

<input type=”hidden” name=”__VIEWSTATE” id=”__VIEWSTATE” value=”/wEPDwUJMjgzMDgzOTgzZGQfI8LfDKmcT0TXZj8jwrxqI6TOIA==” />

</div>

<script type=text/javascript>alert(‘hi’)</script>

 

In the above html snippet, we can see the script embedded before the page controls but after form open tag.

 

RegisterStartupScript Output

<script type=”text/javascript”>

<!–

alert(document.getElementById(‘txtName’).value)// –>

</script>

</form>

</body>

 In the above html snippet, we can see the script embedded after the page controls but before form close tag thus making the script able to access the page controls as I said earlier.

 

Don't be shellfish...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on TumblrEmail this to someone

Leave a Reply