문제

What is the preferred approach for running JavaScript right as an ASP server control is rendered on the page. The documentation is a bit confusing/obtuse.

도움이 되었습니까?

해결책

The documentation prefers that you use the page's ClientScriptManager to render all javascript. I think this is an effort to get you to consolidate javascript into reusable sections, so that you render the javascript once, no matter how many controls you have.

Your way is going to emit javascript for every control. This isn't necessarily bad (especially if you are the only user of your server control).

Basically, you'll just add the script you need as part of the Render phase of the control, and use the HtmlTextWriter to output it (probably just before you return from the Render override). I find it helpful to have helper classes to assist.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top