When writing the project, I want to encapsulate the login foreground script event of ASP, add a BasePage.cs page, but always error "non-static field, method or property" System.Web.UI.Page.ClientScript ... "Requires object reference" '
Original wording:
/// <summary> ///Display the client prompt box/// </summary> /// <param name= "msg" ></param> Public Static voidShowMsg (stringmsg) {Clientscript.registerstartupscript (Clientscript.gettype (),"MyScript","<script type=\ "text/javascript\" >showinmsg ('"+ msg +"');</script>"); }
Workaround:
Change into
/// <summary> ///Display the client prompt box/// </summary> /// <param name= "msg" ></param> Public Static voidShowMsg (stringmsg) {Page page=(Page) System.Web.HttpContext.Current.Handler; Page. Clientscript.registerstartupscript (page. GetType (),"MyScript","<script type=\ "text/javascript\" >showinmsg ('"+ msg +"');</script>"); }
You can do it.
Non-static field, method, or property "System.Web.UI.Page.ClientScript ..." requires an object reference (encapsulates the registration script)