Where is the best part of asp.net page or code behind to register RegisterClientScriptBlock.
Where is the best part of asp.net page or code behind to register RegisterClientScriptBlock
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have a bunch of options.
Register script includes in your
<head>section or do inline<script>tags. I prefer to have my scripts at the bottom of the page though.You can also register it at the
Pagelevel in yourPage_Load(or any other event) by callingClientScript.RegisterClientScriptBlockand passing it the script you want. Remember that if you do go withRegisterClientScriptBlock, you will need to make sure that you register the code with every page load so that is why I would recommend thePage_Loadevent if you want to use this method.For example:
Just make sure you don’t include it the portion of your
Page_Loadthat is wrapped with theif (!IsPostBack)check or else your scripts will not get registered after any postbacks.