locked
GetWebResourceUrl - very frustrated - need help RRS feed

  • Question

  • User888441741 posted

    i'm trying to embeeded resource to the javascript  

    i spent lot of my time figuring out the the cause of the error and the error messages says:  "Error: missing ';' "

    here is what i'm trying to do

    WORKING LINE without any problem:           

    writer.WriteLine("XUtils.addEventListener(window, \"load\", " + funcName + ");");

    ERROR - NOT WORKING LINE                

    writer.WriteLine(this.Page.ClientScript.GetWebResourceUrl(this.GetType(),"project_name.Resources.Js.XUtils.js") + ".addEventListener(window, \"load\", " + funcName + ");");


     

    Saturday, March 15, 2008 2:39 PM

Answers

  • User438584654 posted

    First you need to mark your assembly with this attribute (place it for example in AssemblyInfo.cs file):

    [assembly: WebResource("project_name.Resources.Js.XUtils.js", "application/x-javascript")]
     

     

    Second - register include into the page:

        // Define the resource name and type.
        String rsname = "project_name.Resources.Js.XUtils.js";
        Type rstype = this.GetType();

        // Get a ClientScriptManager reference from the Page class.
        ClientScriptManager cs = Page.ClientScript;

        // Register the client resource with the page.
        cs.RegisterClientScriptResource(rstype, rsname);

     

    Third - Register Start Up Script:

    Page.ClientScript.RegisterStartupScript(this.GetType(), "some_key", "XUtils.addEventListener(window, \"load\", " + funcName + ");", true);

    Hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 15, 2008 5:29 PM

All replies

  • User438584654 posted

    Hi nisarkhan,

    GetWebResourceUrl returns dynamically created url of weresource(something like this: ScriptResource.axd?d=CS4fRDBHBNxmDUtuI5lzv8x2Kp2M1gZBXF1LHH5YCmpSaaaOkyqKrFmKnNZPiFrGvnt60GB8CTXxjIm4gSKuYV4Rinyc8Ooa6PS2iE-NChsSHgS4sN6ezjjAQNPWwibz0&t=633312782948642785 - definitely not the name of the file

    Hope this helps.

    Saturday, March 15, 2008 5:04 PM
  • User888441741 posted

    how do i fix what i want?

    Saturday, March 15, 2008 5:10 PM
  • User438584654 posted

    First you need to mark your assembly with this attribute (place it for example in AssemblyInfo.cs file):

    [assembly: WebResource("project_name.Resources.Js.XUtils.js", "application/x-javascript")]
     

     

    Second - register include into the page:

        // Define the resource name and type.
        String rsname = "project_name.Resources.Js.XUtils.js";
        Type rstype = this.GetType();

        // Get a ClientScriptManager reference from the Page class.
        ClientScriptManager cs = Page.ClientScript;

        // Register the client resource with the page.
        cs.RegisterClientScriptResource(rstype, rsname);

     

    Third - Register Start Up Script:

    Page.ClientScript.RegisterStartupScript(this.GetType(), "some_key", "XUtils.addEventListener(window, \"load\", " + funcName + ");", true);

    Hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 15, 2008 5:29 PM
  • User888441741 posted

    thanks for the reply.

    Saturday, March 15, 2008 9:52 PM