Archive

Posts Tagged ‘Javascripts’

How to register a startup (document).ready(..) script only for the first page load


Snippet

    public partial class Test : Page
    {
        private string script = @"
            $(document).ready(function () {

            });
        ";
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (!this.Page.IsPostBack)
                this.Page.ClientScript.RegisterStartupScript(this.GetType(),
                    this.GetType().Name, this.script, true);
        }
    }