I’m going to use following ClientScript function (VS2010,C#) in a public static method, but it gives me some errors (I want to use it for response redirect with “_parent” target
ClientScript.RegisterStartupScript(GetType(), "Load", "<script type='text/javascript'>window.parent.location.href = '" + a + "'; </script>");
Error 37 An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.ClientScript.get'
Error 38 An object reference is required for the non-static field, method, or property 'object.GetType()'
thanks
You cannot use instance properties (
ClientScript) or methods (GetType()) inside a static methods (basically anything instance).Drop the static keyword and it should work:
EDIT after comment:
Or if you need that the method is static in a static class pass the Page object as a parameter:
Usage (inside a page codebehind):
Side note:
ClientScript.RegisterStartupScripttakes two arguments: the key for the script, and script text, so there is no need for theGetType()there.