Use of RegisterClientScriptBlock/RegisterStartupScript in asp.net 3.5
<p>i am not able to understand what is the use of it.RegisterClientScriptBlock/RegisterStartupScript</p>

<p>when we can direclty write the javascrpt code  in.js file then call it on the button</p>

<p>ex: 2</p>

<pre><code>&lt;script&gt;
    function ReqField1Validator() { 
        if (document.forms[0].txtField1.value == '') {
            alert('TextBox cannot be empty') 
            return false
         } 
         return true 
     } 
&lt;/script&gt;

btnPostback.Attributes.Add("onclick","return ReqField1Validator()");
</code></pre>

<p>what will be the use of RegisterClientScriptBlock/RegisterStartupScript  ?</p>

<pre><code>protected void btnPostback_Click(object sender, EventArgs e)  {
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    sb.Append(@"&lt;script language='javascript'&gt;");
    sb.Append(@"var lbl = document.getElementById('lblDisplayDate');");
    sb.Append(@"lbl.style.color='red';");
    sb.Append(@"&lt;/script&gt;");

    if (!ClientScript.IsStartupScriptRegistered("JSScript")){
        ClientScript.RegisterStartupScript(this.GetType(), "JSScript", sb.ToString());
    }
}
</code></pre>

<p>read few articles but they were not clear</p>

<p>any thoughts on this would be great</p>

<p>Thanks
Prince</p>
