it's a easy essay about the difference in  Response.Write、 ClientScript.RegisterStartupScript、 ClientScript.RegisterClientScriptBlock.

        string message="I have a test now";
        StringBuilder sb = new StringBuilder();
        sb.Append(" <script type=\"text/javascript\"> \n ");
        sb.Append("    alert(\"" + message + "\") \n");
        sb.Append(" </script> \n");

        string function = string.Format("alert('{0}')", message);
        ClientScript.RegisterStartupScript(this.GetType(), "onclick", function, true);

        string function = string.Format("alert('{0}')", message);
        ClientScript.RegisterClientScriptBlock(this.GetType(), "onclick", function, true);

 as you konw ,these three code3 have a the same funtion .

 if you have a test,you will find the differece in them. Actually, the code1 block is equal with code3 block .

 but the code3 block  can help you to improve User Experience,if you don't use the ajax in your solution.

 it's also a dev log for someone who need it.

 the differece in ClientScript.RegisterStartupScript and ClientScript.RegisterClientScriptBlock:

 ClientScript.RegisterClientScriptBlock  adds javascript function block at the right endings of "<form runat="server">" tag of web form.

 and  ClientScript.RegisterStartupScript just appends it above "</form>".
 what about Response.Write? you can figure it out.

 or what about  just  design a demo about it.

Posted on 2008-07-25 17:44  {:)  阅读(693)  评论(0编辑  收藏  举报