What is the difference between ClientScript.RegisterClientScriptBlock and ClientScript.RegisterStartupScript

StackOverflow https://stackoverflow.com/questions/18878024

سؤال

I try to register a script below the however I get it within the

I use the following however did not manage to get it on the place I want it.

if (HttpContext.Current.CurrentHandler is Page)
        {
            Page p = (Page)HttpContext.Current.CurrentHandler;

            if (ScriptManager.GetCurrent(p) != null)
            {                                                                                                                                                                    
                ScriptManager.RegisterStartupScript(p, typeof(string), "_pane", "<script type=\"text/javascript\">var dm = document.getElementById('_pane');dm.addEventListener('dragstart', drag_start, false); </script>", false);
            }
            else
            {
                p.ClientScript.RegisterStartupScript(typeof(Page), "_pane", "<script type=\"text/javascript\">var dm = document.getElementById('_pane');dm.addEventListener('dragstart', drag_start, false); </script>", true);
            }
        }

Pretty sure I miss some details, however after a good research cannot find anything about this, any help would be appriciated

هل كانت مفيدة؟

المحلول

RegisterClientScriptBlock injects script at the top of the page.

RegisterStartupScript injects script into your page such that it will be executed when the page finished loading but before the OnLoad event is fired:

Sources:

ClientScriptManager.RegisterClientScriptBlock Method

ClientScriptManager.RegisterStartupScript Method

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top