The page class provides a clientscript attribute to manage scripts registered in the background, which is most often used to register scripts at the foreground. I think there are two obfuscation-prone Methods: registerclientscriptblock and registerstartupscript. I checked the difference between the two methods carefully and made a record.
Registerclientscriptblock is the front of all HTML elements in form, and the script block is loaded after the viewstate element. If you use HTML elements in the script, you use document. for operations such as getelementbyid, a script error is reported and an object is missing. Because the elements used in your script have not been loaded while the script is running, it is normal to lack objects. Msdn explains: Add a script block at the top of the rendered page.
Registerstartupscript loads script blocks after all HTML elements before </form>. At this time, all HTML elements have been loaded, and document is used. operations such as getelementbyid can be executed normally. In msdn, the added script block is executed before the page load is completed but the onload event of the page is triggered.
The two methods can be used flexibly as needed. If a simple dialog box is displayed, you can use the former. If you need to use HTML elements on the page, use the latter.
Maybe the explanation in msdn is more professional, but I think my understanding is more straightforward.