Does Page.ClientScript available been used in class.cs?

You are having problems because it looks like you are using a class which doesn't derive from System.Web.UI.Page. However, as long as you have access to HttpContext, you can just say:

using System.Web;
using System.Web.UI;

...

var page = HttpContext.Current.CurrentHandler as Page;

if( page == null ){
     // throw an exception, something bad happened
}

// now you have access to the current page...
page.ClientScript.RegisterStartupScript();

Comments

  1. Wilder

    • 2019/8/12

    , not a class itself as a package of some members (in fact, static members, only static members can be accessed without the image).

  2. Elian

    • 2019/4/13

    Does Page.ClientScript available been used in class.cs? Ask Question Asked 9 years, 1 month ago. Active 7 years, 7 months ago. Viewed 7k times

  3. Joshua

    • 2019/12/16

    You are having problems because it looks like you are using a class which doesn't derive from System.Web.UI.Page . However, as long as you 

  4. Steven

    • 2019/1/12

    The name System.Web.UI.Page.ClientScript is an instance property, so it need an access to some existing instance of some class, not a class itself as a package of some members (in fact, static members, only static members can be accessed without the image). An instance property assume access to some object which is different per declaring type

  5. Derek

    • 2015/4/27

    Gets a ClientScriptManager object used to manage, register, and add script to the page. The ClientScriptManager class is new in ASP.

  6. Bryant

    • 2015/5/26

    3 Does Page.ClientScript available been used in class.cs? Aug 10 '12. 0 How to call a class from a cs file to update or save the session expired in database? Aug 7 '12.

  7. Enrique

    • 2017/8/3

    Hello,I am trying to use the RegisterStartupScript and RegisterClientScriptBlock Methods of the Page Class in VB.NET and C#. Below is a pared 

  8. Collin

    • 2015/6/20

    File: UI\Page.cs Project: ndp\fx\src\xsp\system\Web\System.Web.csproj (System.Web) //-----// <copyright file="Page.cs" company="Microsoft"> // Copyright (c) Microsoft

  9. Jerome

    • 2017/4/28

    RegisterStartupScript(cstype, csname1, cstext1); } // Check to see if the client script is already registered. if (!cs.

  10. Romano

    • 2019/6/21

    The base page class can be Page, or it can be another class that derives from Page. Furthermore, note that the partial class allows the code-behind file to use controls defined on the page without the need to define them as field members. using System; public partial class MyCodeBehindCS : System.Web.UI.Page { protected void Page_Load(object

  11. Merrick

    • 2016/5/24

    Script includes are used to store JavaScript that runs on the server. they are active or not, and whether they can be called from a client script.

  12. Delvina

    • 2020/5/25

    So this class acts as a go between that checks whether MS Ajax is available and if it is calls ScriptManager, otherwise calls standard Page.ClientScript. The idea is that a control developer can add an instance of this class and then simply use it to make the ClientScript calls on it instead.

  13. Milo

    • 2018/8/5

    You should rather use the ScriptManager class, since the Page.ClientScript property is deprecated The ClientScriptManager class is new in ASP.

  14. Jaxson

    • 2017/6/27

    Simone, good idea, although I'm not sure that this is really necessary for ClientScript or ScriptManager. Those objects are already singletons (ClientScript on Page and ScriptManager because it's static) and this class is merely getting references to those objects - it's not creating new ones, so there should be no issue with the script entries getting duplicated.

  15. Aayan

    • 2017/12/10

    When running the page, you can view the source code for the page to see the action="Listing04-09.aspx" id="form1"> <div class="aspNetHidden"> <input 

  16. Izaiah

    • 2015/6/20

    Unfortunately, this approach is tedious and often impractical. To use this approach, you must call the Page.ClientScript.RegisterForEventValidation() method 

Comments are closed.

Recent Posts