ClientScript.RegisterClientScriptInclude -

Discussion in 'ASP .Net' started by Dariusz Tomoñ, Aug 5, 2007.

  1. Hello,

    I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not directly
    from i.e. default.aspx.cs code but from a class belonging to DLL, which is
    referred in my project.

    The code is as follow:

    Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");

    string scriptBlock = "<script type=\"text/javascript\"
    language=\"JavaScript\">" +

    "var fo = new SWFObject(\"" + path + "\", \"\", \""+szerokosc+"\",
    \""+wysokosc+"\", \"6\", \"#FFFFFF\");" +

    "fo.write(\"" + layer + "\");" +

    "</script>";

    All the time I get error in the line -
    Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    telling that reference to the object is not set for object occurence (I
    cannot provide the error message because it's in my language - I have got
    polish version of Win2003Serv. At the occasion: Is it possible to force my
    environment to throw english errors not polish?).


    I tried to change Page.GetType() to this.GetType() but without any effect.

    Thank you for any suggestion.

    Darek T.
    Dariusz Tomoñ, Aug 5, 2007
    #1
    1. Advertising

  2. "Dariusz Tomoñ" <> wrote in message
    news:%...

    > I tried to change Page.GetType() to this.GetType() but without any effect.


    this.GetType() is correct... However, the third argument of the
    RegisterClientScriptInclude method is, in fact, a URL - does the
    swfobject.js file exist in the same folder as the page which is trying to
    reference it...?
    http://msdn2.microsoft.com/en-us/library/kx145dw2(VS.80).aspx


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Aug 5, 2007
    #2
    1. Advertising

  3. Dariusz Tomoñ

    Stan SR Guest

    Hi,

    Did you try this ?

    ClientScript.RegisterClientScriptBlock(this.GetType(), "swobject",
    scriptBlock);

    Hth
    Stan


    "Dariusz Tomoñ" <> a écrit dans le message de
    news:%...
    > Hello,
    >
    > I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not directly
    > from i.e. default.aspx.cs code but from a class belonging to DLL, which is
    > referred in my project.
    >
    > The code is as follow:
    >
    > Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    >
    > string scriptBlock = "<script type=\"text/javascript\"
    > language=\"JavaScript\">" +
    >
    > "var fo = new SWFObject(\"" + path + "\", \"\", \""+szerokosc+"\",
    > \""+wysokosc+"\", \"6\", \"#FFFFFF\");" +
    >
    > "fo.write(\"" + layer + "\");" +
    >
    > "</script>";
    >
    > All the time I get error in the line -
    > Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    > telling that reference to the object is not set for object occurence (I
    > cannot provide the error message because it's in my language - I have got
    > polish version of Win2003Serv. At the occasion: Is it possible to force my
    > environment to throw english errors not polish?).
    >
    >
    > I tried to change Page.GetType() to this.GetType() but without any effect.
    >
    > Thank you for any suggestion.
    >
    > Darek T.
    >
    >
    Stan SR, Aug 5, 2007
    #3
  4. Dariusz,

    you will need to call it as follows:

    page..ClientScript.RegisterClientScriptInclude(page.GetType(), ...

    where page will be the reference to the page on which you are trying to
    register your script.


    "Dariusz Tomoñ" wrote:

    > Hello,
    >
    > I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not directly
    > from i.e. default.aspx.cs code but from a class belonging to DLL, which is
    > referred in my project.
    >
    > The code is as follow:
    >
    > Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    >
    > string scriptBlock = "<script type=\"text/javascript\"
    > language=\"JavaScript\">" +
    >
    > "var fo = new SWFObject(\"" + path + "\", \"\", \""+szerokosc+"\",
    > \""+wysokosc+"\", \"6\", \"#FFFFFF\");" +
    >
    > "fo.write(\"" + layer + "\");" +
    >
    > "</script>";
    >
    > All the time I get error in the line -
    > Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    > telling that reference to the object is not set for object occurence (I
    > cannot provide the error message because it's in my language - I have got
    > polish version of Win2003Serv. At the occasion: Is it possible to force my
    > environment to throw english errors not polish?).
    >
    >
    > I tried to change Page.GetType() to this.GetType() but without any effect.
    >
    > Thank you for any suggestion.
    >
    > Darek T.
    >
    >
    >
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Aug 6, 2007
    #4
  5. ok, but 'this' is not my Page object, rather: -
    EuroAdresBasic.EFlashControl2, where EuroAdresBasic is namespace and
    EFlashControl2 is a class from within I'm trying to reffer to my Page
    object.
    I tried to someting like that:
    Page page = new Page();

    but in reality it is not my Page where I want to inject JS so I cannot see
    my swf injected.



    Best Regards

    Darek




    Uzytkownik "Mark Rae [MVP]" <> napisal w wiadomosci
    news:...
    > "Dariusz Tomoñ" <> wrote in message
    > news:%...
    >
    >> I tried to change Page.GetType() to this.GetType() but without any
    >> effect.

    >
    > this.GetType() is correct... However, the third argument of the
    > RegisterClientScriptInclude method is, in fact, a URL - does the
    > swfobject.js file exist in the same folder as the page which is trying to
    > reference it...?
    > http://msdn2.microsoft.com/en-us/library/kx145dw2(VS.80).aspx
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    Dariusz Tomon, Aug 6, 2007
    #5
  6. ok, but 'this' is not my Page object, rather: -
    EuroAdresBasic.EFlashControl2, where EuroAdresBasic is namespace and
    EFlashControl2 is a class from within I'm trying to reffer to my Page object
    (Page is null)
    I tried to someting like that:
    Page page = new Page();

    but in reality it is not my Page where I want to inject JS so I cannot see
    my swf injected.

    Best Regards

    Darek

    Uzytkownik "Stan SR" <> napisal w wiadomosci
    news:...
    > Hi,
    >
    > Did you try this ?
    >
    > ClientScript.RegisterClientScriptBlock(this.GetType(), "swobject",
    > scriptBlock);
    >
    > Hth
    > Stan
    >
    >
    > "Dariusz Tomoñ" <> a écrit dans le message de
    > news:%...
    >> Hello,
    >>
    >> I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not
    >> directly from i.e. default.aspx.cs code but from a class belonging to
    >> DLL, which is referred in my project.
    >>
    >> The code is as follow:
    >>
    >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    >>
    >> string scriptBlock = "<script type=\"text/javascript\"
    >> language=\"JavaScript\">" +
    >>
    >> "var fo = new SWFObject(\"" + path + "\", \"\", \""+szerokosc+"\",
    >> \""+wysokosc+"\", \"6\", \"#FFFFFF\");" +
    >>
    >> "fo.write(\"" + layer + "\");" +
    >>
    >> "</script>";
    >>
    >> All the time I get error in the line -
    >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    >> telling that reference to the object is not set for object occurence (I
    >> cannot provide the error message because it's in my language - I have got
    >> polish version of Win2003Serv. At the occasion: Is it possible to force
    >> my environment to throw english errors not polish?).
    >>
    >>
    >> I tried to change Page.GetType() to this.GetType() but without any
    >> effect.
    >>
    >> Thank you for any suggestion.
    >>
    >> Darek T.
    >>
    >>

    >
    Dariusz Tomon, Aug 6, 2007
    #6
  7. ok, but I don't know hot to reffer to my Page object (during executing this
    line 'Page' is null. Other guys suggested using 'this' but 'this' is not my
    Page object, rather: - EuroAdresBasic.EFlashControl2, where EuroAdresBasic
    is namespace and EFlashControl2 is a class from within I'm trying to reffer
    to my Page object (Page is null)
    I tried to someting like that:
    Page page = new Page();

    but in reality it is not my Page where I want to inject JS so I cannot see
    my swf injected.

    The question is how to reffer to my Page from external project (the class is
    in external project)

    Best Regards

    Darek

    U¿ytkownik "Sergey Poberezovskiy"
    <> napisa³ w wiadomo¶ci
    news:...
    > Dariusz,
    >
    > you will need to call it as follows:
    >
    > page..ClientScript.RegisterClientScriptInclude(page.GetType(), ...
    >
    > where page will be the reference to the page on which you are trying to
    > register your script.
    >
    >
    > "Dariusz Tomon" wrote:
    >
    >> Hello,
    >>
    >> I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not
    >> directly
    >> from i.e. default.aspx.cs code but from a class belonging to DLL, which
    >> is
    >> referred in my project.
    >>
    >> The code is as follow:
    >>
    >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    >>
    >> string scriptBlock = "<script type=\"text/javascript\"
    >> language=\"JavaScript\">" +
    >>
    >> "var fo = new SWFObject(\"" + path + "\", \"\", \""+szerokosc+"\",
    >> \""+wysokosc+"\", \"6\", \"#FFFFFF\");" +
    >>
    >> "fo.write(\"" + layer + "\");" +
    >>
    >> "</script>";
    >>
    >> All the time I get error in the line -
    >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    >> telling that reference to the object is not set for object occurence (I
    >> cannot provide the error message because it's in my language - I have got
    >> polish version of Win2003Serv. At the occasion: Is it possible to force
    >> my
    >> environment to throw english errors not polish?).
    >>
    >>
    >> I tried to change Page.GetType() to this.GetType() but without any
    >> effect.
    >>
    >> Thank you for any suggestion.
    >>
    >> Darek T.
    >>
    >>
    >>
    Dariusz Tomoñ, Aug 6, 2007
    #7
  8. Darek,

    If you have a control that resides on the page you after, then you can use
    it's Page property. If you say that your control's Page property is null, it
    looks like you are trying to reference it too early in the control's lifetime
    (before the control is added to the page controls hierarchy).

    I usually register all my scripts in PreRender event - this way you do not
    execute unnecessary code if, say in other control's events the current page
    terminates (if Response is redirected, transferred or otherwise ended).

    "Dariusz Tomoñ" wrote:

    > ok, but I don't know hot to reffer to my Page object (during executing this
    > line 'Page' is null. Other guys suggested using 'this' but 'this' is not my
    > Page object, rather: - EuroAdresBasic.EFlashControl2, where EuroAdresBasic
    > is namespace and EFlashControl2 is a class from within I'm trying to reffer
    > to my Page object (Page is null)
    > I tried to someting like that:
    > Page page = new Page();
    >
    > but in reality it is not my Page where I want to inject JS so I cannot see
    > my swf injected.
    >
    > The question is how to reffer to my Page from external project (the class is
    > in external project)
    >
    > Best Regards
    >
    > Darek
    >
    > U¿ytkownik "Sergey Poberezovskiy"
    > <> napisa³ w wiadomo¶ci
    > news:...
    > > Dariusz,
    > >
    > > you will need to call it as follows:
    > >
    > > page..ClientScript.RegisterClientScriptInclude(page.GetType(), ...
    > >
    > > where page will be the reference to the page on which you are trying to
    > > register your script.
    > >
    > >
    > > "Dariusz Tomon" wrote:
    > >
    > >> Hello,
    > >>
    > >> I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not
    > >> directly
    > >> from i.e. default.aspx.cs code but from a class belonging to DLL, which
    > >> is
    > >> referred in my project.
    > >>
    > >> The code is as follow:
    > >>
    > >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    > >>
    > >> string scriptBlock = "<script type=\"text/javascript\"
    > >> language=\"JavaScript\">" +
    > >>
    > >> "var fo = new SWFObject(\"" + path + "\", \"\", \""+szerokosc+"\",
    > >> \""+wysokosc+"\", \"6\", \"#FFFFFF\");" +
    > >>
    > >> "fo.write(\"" + layer + "\");" +
    > >>
    > >> "</script>";
    > >>
    > >> All the time I get error in the line -
    > >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    > >> telling that reference to the object is not set for object occurence (I
    > >> cannot provide the error message because it's in my language - I have got
    > >> polish version of Win2003Serv. At the occasion: Is it possible to force
    > >> my
    > >> environment to throw english errors not polish?).
    > >>
    > >>
    > >> I tried to change Page.GetType() to this.GetType() but without any
    > >> effect.
    > >>
    > >> Thank you for any suggestion.
    > >>
    > >> Darek T.
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Aug 6, 2007
    #8
  9. Dear Sergey,

    I eventually got by ... but I had to pass on my Page object as parameter to
    external class. Yes, before calling external class code I have value of Page
    object and when I call the code of the dll my Page object seems to be
    reseted to null (therefore I thought of passing it as parameter). Now it
    works but I'm wondering if there is other method ...
    I have no idea how can I invoke the code from external class using PreRender
    event. I'm doing it from within code so I have no graphical representation
    of external class and therefore I have no access to events in my VS2005.
    Can you share a snippet of code with me?

    My calling is like this:
    EuroAdresBasic.EFlashControl2 fleszcontrol = new EFlashControl2(Page,
    "panel", "http://www.euroadres.pl/images/flash/" + flesz, "360", "340");

    And a snippet from EFlasControl2 is like below:

    public class EFlashControl2 : System.Web.UI.WebControls.WebControl

    {

    protected System.Web.UI.HtmlControls.HtmlGenericControl FlashObject

    = new System.Web.UI.HtmlControls.HtmlGenericControl("object");

    protected System.Web.UI.HtmlControls.HtmlGenericControl FlashParam

    = new System.Web.UI.HtmlControls.HtmlGenericControl("param");

    protected System.Web.UI.HtmlControls.HtmlGenericControl FlashEmbed

    = new System.Web.UI.HtmlControls.HtmlGenericControl("embed");

    protected System.Web.UI.HtmlControls.HtmlGenericControl pr;

    public EFlashControl2(Page PageObject, string layer, string path, string
    szerokosc, string wysokosc)

    {

    //Page page = new Page();



    Random RandomClass = new Random();

    int RandomNumber = RandomClass.Next(0, 90000);

    string SWFObjectName = RandomNumber.ToString();



    PageObject.ClientScript.RegisterClientScriptInclude(PageObject.GetType(),
    "swfobject.js", "swfobject.js");

    string scriptBlock = "<script type=\"text/javascript\"
    language=\"JavaScript\">" +

    "var fo = new SWFObject(\"" + path + "\", \"" + SWFObjectName + "\", \"" +
    szerokosc + "\", \"" + wysokosc + "\", \"6\", \"#FFFFFF\");" +

    "fo.write(\"" + layer + "\");" +

    "</script>";

    PageObject.ClientScript.RegisterClientScriptBlock(PageObject.GetType(),
    layer, scriptBlock);



    Best Regards



    Darek T.


    U¿ytkownik "Sergey Poberezovskiy"
    <> napisa³ w wiadomo¶ci
    news:D...
    > Darek,
    >
    > If you have a control that resides on the page you after, then you can use
    > it's Page property. If you say that your control's Page property is null,
    > it
    > looks like you are trying to reference it too early in the control's
    > lifetime
    > (before the control is added to the page controls hierarchy).
    > ahe
    > I usually register all my scripts in PreRender event - this way you do not
    > execute unnecessary code if, say in other control's events the current
    > page
    > terminates (if Response is redirected, transferred or otherwise ended).
    >
    > "Dariusz Tomon" wrote:
    >
    >> ok, but I don't know hot to reffer to my Page object (during executing
    >> this
    >> line 'Page' is null. Other guys suggested using 'this' but 'this' is not
    >> my
    >> Page object, rather: - EuroAdresBasic.EFlashControl2, where
    >> EuroAdresBasic
    >> is namespace and EFlashControl2 is a class from within I'm trying to
    >> reffer
    >> to my Page object (Page is null)
    >> I tried to someting like that:
    >> Page page = new Page();
    >>
    >> but in reality it is not my Page where I want to inject JS so I cannot
    >> see
    >> my swf injected.
    >>
    >> The question is how to reffer to my Page from external project (the class
    >> is
    >> in external project)
    >>
    >> Best Regards
    >>
    >> Darek
    >>
    >> U?ytkownik "Sergey Poberezovskiy"
    >> <> napisa3 w wiadomo?ci
    >> news:...
    >> > Dariusz,
    >> >
    >> > you will need to call it as follows:
    >> >
    >> > page..ClientScript.RegisterClientScriptInclude(page.GetType(), ...
    >> >
    >> > where page will be the reference to the page on which you are trying to
    >> > register your script.
    >> >
    >> >
    >> > "Dariusz Tomon" wrote:
    >> >
    >> >> Hello,
    >> >>
    >> >> I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not
    >> >> directly
    >> >> from i.e. default.aspx.cs code but from a class belonging to DLL,
    >> >> which
    >> >> is
    >> >> referred in my project.
    >> >>
    >> >> The code is as follow:
    >> >>
    >> >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    >> >>
    >> >> string scriptBlock = "<script type=\"text/javascript\"
    >> >> language=\"JavaScript\">" +
    >> >>
    >> >> "var fo = new SWFObject(\"" + path + "\", \"\", \""+szerokosc+"\",
    >> >> \""+wysokosc+"\", \"6\", \"#FFFFFF\");" +
    >> >>
    >> >> "fo.write(\"" + layer + "\");" +
    >> >>
    >> >> "</script>";
    >> >>
    >> >> All the time I get error in the line -
    >> >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    >> >> telling that reference to the object is not set for object occurence
    >> >> (I
    >> >> cannot provide the error message because it's in my language - I have
    >> >> got
    >> >> polish version of Win2003Serv. At the occasion: Is it possible to
    >> >> force
    >> >> my
    >> >> environment to throw english errors not polish?).
    >> >>
    >> >>
    >> >> I tried to change Page.GetType() to this.GetType() but without any
    >> >> effect.
    >> >>
    >> >> Thank you for any suggestion.
    >> >>
    >> >> Darek T.
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
    Dariusz Tomoñ, Aug 7, 2007
    #9
  10. Darek,

    Your EFlashControl2 inherits WebControl and therefore can override its
    virtual methods (as you may not assume that AutoEventWireup is set to true on
    the page).
    something similar to the following:

    protected override void OnPreRender(EventArgs e)
    {
    if (this.Page != null){
    string scriptBlock = "...";
    this.Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), ...
    }
    base.OnPreRender(e);
    }

    the reason I included check on whether the Page property is not empty is
    that control may not necessarily ends up rendered on the page, but sometimes
    into a stringbuilder instead.


    "Dariusz Tomoñ" wrote:

    > Dear Sergey,
    >
    > I eventually got by ... but I had to pass on my Page object as parameter to
    > external class. Yes, before calling external class code I have value of Page
    > object and when I call the code of the dll my Page object seems to be
    > reseted to null (therefore I thought of passing it as parameter). Now it
    > works but I'm wondering if there is other method ...
    > I have no idea how can I invoke the code from external class using PreRender
    > event. I'm doing it from within code so I have no graphical representation
    > of external class and therefore I have no access to events in my VS2005.
    > Can you share a snippet of code with me?
    >
    > My calling is like this:
    > EuroAdresBasic.EFlashControl2 fleszcontrol = new EFlashControl2(Page,
    > "panel", "http://www.euroadres.pl/images/flash/" + flesz, "360", "340");
    >
    > And a snippet from EFlasControl2 is like below:
    >
    > public class EFlashControl2 : System.Web.UI.WebControls.WebControl
    >
    > {
    >
    > protected System.Web.UI.HtmlControls.HtmlGenericControl FlashObject
    >
    > = new System.Web.UI.HtmlControls.HtmlGenericControl("object");
    >
    > protected System.Web.UI.HtmlControls.HtmlGenericControl FlashParam
    >
    > = new System.Web.UI.HtmlControls.HtmlGenericControl("param");
    >
    > protected System.Web.UI.HtmlControls.HtmlGenericControl FlashEmbed
    >
    > = new System.Web.UI.HtmlControls.HtmlGenericControl("embed");
    >
    > protected System.Web.UI.HtmlControls.HtmlGenericControl pr;
    >
    > public EFlashControl2(Page PageObject, string layer, string path, string
    > szerokosc, string wysokosc)
    >
    > {
    >
    > //Page page = new Page();
    >
    >
    >
    > Random RandomClass = new Random();
    >
    > int RandomNumber = RandomClass.Next(0, 90000);
    >
    > string SWFObjectName = RandomNumber.ToString();
    >
    >
    >
    > PageObject.ClientScript.RegisterClientScriptInclude(PageObject.GetType(),
    > "swfobject.js", "swfobject.js");
    >
    > string scriptBlock = "<script type=\"text/javascript\"
    > language=\"JavaScript\">" +
    >
    > "var fo = new SWFObject(\"" + path + "\", \"" + SWFObjectName + "\", \"" +
    > szerokosc + "\", \"" + wysokosc + "\", \"6\", \"#FFFFFF\");" +
    >
    > "fo.write(\"" + layer + "\");" +
    >
    > "</script>";
    >
    > PageObject.ClientScript.RegisterClientScriptBlock(PageObject.GetType(),
    > layer, scriptBlock);
    >
    >
    >
    > Best Regards
    >
    >
    >
    > Darek T.
    >
    >
    > U¿ytkownik "Sergey Poberezovskiy"
    > <> napisa³ w wiadomo¶ci
    > news:D...
    > > Darek,
    > >
    > > If you have a control that resides on the page you after, then you can use
    > > it's Page property. If you say that your control's Page property is null,
    > > it
    > > looks like you are trying to reference it too early in the control's
    > > lifetime
    > > (before the control is added to the page controls hierarchy).
    > > ahe
    > > I usually register all my scripts in PreRender event - this way you do not
    > > execute unnecessary code if, say in other control's events the current
    > > page
    > > terminates (if Response is redirected, transferred or otherwise ended).
    > >
    > > "Dariusz Tomon" wrote:
    > >
    > >> ok, but I don't know hot to reffer to my Page object (during executing
    > >> this
    > >> line 'Page' is null. Other guys suggested using 'this' but 'this' is not
    > >> my
    > >> Page object, rather: - EuroAdresBasic.EFlashControl2, where
    > >> EuroAdresBasic
    > >> is namespace and EFlashControl2 is a class from within I'm trying to
    > >> reffer
    > >> to my Page object (Page is null)
    > >> I tried to someting like that:
    > >> Page page = new Page();
    > >>
    > >> but in reality it is not my Page where I want to inject JS so I cannot
    > >> see
    > >> my swf injected.
    > >>
    > >> The question is how to reffer to my Page from external project (the class
    > >> is
    > >> in external project)
    > >>
    > >> Best Regards
    > >>
    > >> Darek
    > >>
    > >> U?ytkownik "Sergey Poberezovskiy"
    > >> <> napisa3 w wiadomo?ci
    > >> news:...
    > >> > Dariusz,
    > >> >
    > >> > you will need to call it as follows:
    > >> >
    > >> > page..ClientScript.RegisterClientScriptInclude(page.GetType(), ...
    > >> >
    > >> > where page will be the reference to the page on which you are trying to
    > >> > register your script.
    > >> >
    > >> >
    > >> > "Dariusz Tomon" wrote:
    > >> >
    > >> >> Hello,
    > >> >>
    > >> >> I'd like to include JS from C# code (ASP.NET 2.0). I'm trying not
    > >> >> directly
    > >> >> from i.e. default.aspx.cs code but from a class belonging to DLL,
    > >> >> which
    > >> >> is
    > >> >> referred in my project.
    > >> >>
    > >> >> The code is as follow:
    > >> >>
    > >> >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    > >> >>
    > >> >> string scriptBlock = "<script type=\"text/javascript\"
    > >> >> language=\"JavaScript\">" +
    > >> >>
    > >> >> "var fo = new SWFObject(\"" + path + "\", \"\", \""+szerokosc+"\",
    > >> >> \""+wysokosc+"\", \"6\", \"#FFFFFF\");" +
    > >> >>
    > >> >> "fo.write(\"" + layer + "\");" +
    > >> >>
    > >> >> "</script>";
    > >> >>
    > >> >> All the time I get error in the line -
    > >> >> Page.ClientScript.RegisterClientScriptInclude(Page.GetType(),"swfobject.js","swfobject.js");
    > >> >> telling that reference to the object is not set for object occurence
    > >> >> (I
    > >> >> cannot provide the error message because it's in my language - I have
    > >> >> got
    > >> >> polish version of Win2003Serv. At the occasion: Is it possible to
    > >> >> force
    > >> >> my
    > >> >> environment to throw english errors not polish?).
    > >> >>
    > >> >>
    > >> >> I tried to change Page.GetType() to this.GetType() but without any
    > >> >> effect.
    > >> >>
    > >> >> Thank you for any suggestion.
    > >> >>
    > >> >> Darek T.
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >>

    >
    >
    >
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Aug 8, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. verci
    Replies:
    0
    Views:
    364
    verci
    Feb 22, 2007
  2. verci
    Replies:
    1
    Views:
    418
    Teemu Keiski
    Feb 25, 2007
  3. verci
    Replies:
    1
    Views:
    427
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Feb 22, 2007
  4. verci
    Replies:
    2
    Views:
    3,019
    verci
    Feb 23, 2007
  5. verci
    Replies:
    2
    Views:
    567
    verci
    Feb 23, 2007
Loading...

Share This Page