The. net user control ascx. cs fails to register the js script code. ascx. csjs
I encountered a strange problem in the. net web project. I didn't find a solution on the Internet. I 'd like to mark it myself first.
Problem description:
Add a user control ascx and add a js registration script in backend. cs. No pop-up box is displayed after execution.
The registration script is:
This. page. clientScript. registerStartupScript (this. getType (), "", "<script type = 'text/javascript '> alert ('hprompt'); </script>"); this. page. clientScript. registerClientScriptBlock (this. getType (), "", "<script type = 'text/javascript '> alert ('hprompt'); </script> ");
I found some information online and added the registration code on the backend cs page of aspx.
ClientScript. RegisterStartupScript (this. GetType (), "", "<script type = 'text/javascript '> alert ('hprompt'); </script> ");
The alert box is displayed after the script registered on the backend cs page of The aspx page is executed.
Comparing the two pieces of code, I personally think it is because in ascx. this. page does not get the current aspx Page, the script is not successfully registered, but this. the current aspx Page is displayed.