Including Java Scripts in Server controls

Discussion in 'ASP .Net Building Controls' started by Sundararajan, Apr 12, 2005.

  1. Sundararajan

    Sundararajan Guest

    Dear Folks,

    I am developing a server control as a composite control. I need to
    associate some javascripts with the individual controls of the composite
    control.
    I have the javascrips in a separate .js file. how can i associate the
    functions in .js file with the server controls.

    Thanx in advance

    Regards,
     
    Sundararajan, Apr 12, 2005
    #1
    1. Advertisements

  2. hi,

    Add an include line to link the js file to your page,
    This can be done using Page.Registerstartupscript("Key","Script")
    Once the js file is linked with ur page, you can assign the methods in the
    js file to the control events.
    Ex: btnButton.Attributes.Add("OnClick", "YourJSfunction");

    play around with this and you'll get to know a lot more...

    Regds
    Kannan.V
     
    Kannan.V [MCSD.net], Apr 12, 2005
    #2
    1. Advertisements

  3. hi,

    Add an include line to link the js file to your page,
    This can be done using Page.Registerstartupscript("Key","Script")
    Once the js file is linked with ur page, you can assign the methods in the
    js file to the control events.
    Ex: btnButton.Attributes.Add("OnClick", "YourJSfunction");

    play around with this and you'll get to know a lot more...

    Regds
    Kannan.V
     
    Kannan.V [MCSD.net], Apr 12, 2005
    #3
  4. Sundararajan

    Brock Allen Guest

    You want Page.RegisterClientScriptBlock to register a block of functions.
    You'll need to add your own <script language=...> in your script (the 2nd
    param to the method).
     
    Brock Allen, Apr 12, 2005
    #4
  5. Sundararajan

    Dale Preston Guest

    In your server control, do something like:

    Response.Write("<script src='" + myScriptFileUrl + "'></script>");

    That will cause the browser to load the javascript file.

    HTH

    Dale Preston
    MCAD, MCDBA, MCSE
     
    Dale Preston, Apr 13, 2005
    #5
  6. Sundararajan

    Sundararajan Guest

    Hi,

    however in this the registerstartupscript methog requires the script be
    passed as string. but i have it a separate file and i want to refer to that
    file by using the url. is that possible. or should i read from the url and
    convert it into a string and then use this method.

    regards,
    sundararajan.s
     
    Sundararajan, Apr 13, 2005
    #6
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.